Found 1034 Articles for Matplotlib

How to visualize values on logarithmic scale on matplotalib?

Rishikesh Kumar Rishi
Updated on 01-Feb-2022 11:20:03

4K+ Views

To visualize values on logarithmic scale on matplotlib, we can use yscale('log').StepsImport matplotlib nd numpy.Set the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Use yscale('log') to visualize the values on a logarithmic scale.Plot x and y data points using plot method.Place a legend on the figure.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # x and y data points x = np.linspace(1, 100, 1000) y = np.log(x) ... Read More

How to change xticks font size in a matplotlib plot?

Rishikesh Kumar Rishi
Updated on 08-Sep-2023 23:25:53

36K+ Views

To change the font size of xticks in a matplotlib plot, we can use the fontsize parameter.StepsImport matplotlib and numpy.Set the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Plot the x and y data points using plot() method.Set the font size of xticks using xticks() method.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import numpy as np # Set the figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # x and y data points x = np.linspace(-5, 5, 100) y = np.sin(x) ... Read More

How to plot multiple horizontal bars in one chart with matplotlib?

Rishikesh Kumar Rishi
Updated on 01-Feb-2022 11:14:19

2K+ Views

To plot multiple horizontal bars in one chart with matplotlib, we can take the following steps −StepsImport the libraries pandas, matplotlib, and numpy.Set the figure size and adjust the padding between and around the subplots.Create an array for horizontal bar's position.Initialize a variable width for bar's width.Create a horizontal bar plot.Set Y-axis ticks and tick labels with some limit.Place a legend on the plot at the upper right location.To display the figure, use show() method.Exampleimport pandas import matplotlib.pyplot as plt import numpy as np # Set the figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Array ... Read More

How to shift the colorbar position to right in matplotlib?

Rishikesh Kumar Rishi
Updated on 01-Feb-2022 11:11:11

2K+ Views

To shift the colorbar position to right in matplotlib, we can take the following steps −StepsImport numpy and matplotlib.Set the figure size and adjust the padding between and around the subplots.Initialize a variable N to store the number of sample data.Create x and y data points using numpy.Create a scatter plot using scatter() method with x and y data points.Add a colorbar to a plot, use the pad value for horizontal shift towards right or left.To display the figure, use show() method.Example# Import numpy and matplotlib import numpy as np from matplotlib import pyplot as plt # Set the ... Read More

How to set the value of the axis multiplier in matplotlib?

Rishikesh Kumar Rishi
Updated on 01-Feb-2022 11:07:43

1K+ Views

To set the value of the axis multiplier in matplotlib, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create x data points using numpy.Plot x and x2 using plot() method.Get the current axis of the figure.Initialize a variable multiplier, i.e., a value of the axis multiplier.Set a tick on each integer multiple of a base within the view interval.Set the locator of the major ticker.To display the figure, use show() method.Example# Import matplotlib and numpy from matplotlib import pyplot as plt import numpy as np # Set the figure ... Read More

How to curve text in a polar plot in matplotlib?

Rishikesh Kumar Rishi
Updated on 19-Oct-2021 08:41:45

527 Views

To curve text in a polar plot in matplotlib we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Add an 'ax' to the figure as part of a subplot arrangement.Plot the line with some degree, color='green' and linewidth=2.Create x and y data points, with some curve and plot them using plot() method.To display the figure, use Show() method.Examplefrom matplotlib import pyplot as plt from scipy.interpolate import interp1d import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax ... Read More

Animation with contours in matplotlib

Rishikesh Kumar Rishi
Updated on 19-Oct-2021 09:10:27

3K+ Views

To animate with contours in matplotlib, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create data for the contour plot.Create a figure and a set of subplots.Generate an animation by repeatedly calling a function *animate* where the animate() method changes the contour data points.To display the figure, use Show() method.Exampleimport numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Random data for the contour plot data = np.random.randn(800).reshape(10, 10, 8) # Create a ... Read More

Matplotlib – Difference between plt.subplots() and plt.figure()

Rishikesh Kumar Rishi
Updated on 11-Oct-2021 08:34:26

1K+ Views

plt.figure() − Creates a new figure or activates an existing figure.plt.subplots() − Creates a figure and a set of subplots.Let's take an example to understand the difference between plt.subplots() and plt.figure().StepsSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure. Use plt.figure() method.Create a figure and a set of subplots. Use plt.subplots() method.To display the figure, use Show() method.Examplefrom matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create a new figure using plt.figure fig1 = plt.figure("Figure 1 ... Read More

How get the (x,y) position pointing with mouse in an interactive plot (Python Matplotlib)?

Rishikesh Kumar Rishi
Updated on 19-Oct-2021 08:36:26

4K+ Views

To get the (x, y) positions pointing with mouse in an interactive plot, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Bind the function *mouse_event* to the event *button_press_event*.Create x and y data points using numpy.Plot the x and y data points using plot() method.To display the figure, use Show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True def mouse_event(event): print('x: {} and y: {}'.format(event.xdata, event.ydata)) fig = ... Read More

Matplotlib – How to show the coordinates of a point upon mouse click?

Rishikesh Kumar Rishi
Updated on 11-Oct-2021 08:29:32

6K+ Views

To create a custom mouse cursor in matplotlib, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Bind the function *mouse_event* to the event *button_press_event*.Create x and y data points using numpy.Plot the x and y data points using plot() method.To display the figure, use Show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True def mouse_event(event):     print('x: {} and y: {}'.format(event.xdata, event.ydata)) fig = plt.figure() cid = fig.canvas.mpl_connect('button_press_event', mouse_event) ... Read More

Advertisements