Articles on Trending Technologies

Technical articles with clear explanations and examples

How to save Matplotlib 3d rotating plots?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 16-Jun-2021 6K+ Views

To save Matplotlib 3d roatating plots, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Add an '~.axes.Axes' to the figure as part of a subplot arrangement.Return a tuple X, Y, Z with a test data set.Plot a 3D wireframe.Rotate the axis with an angle.Redraw the current figure.Run the GUI event loop for some seconds.To display the figure, use show() method.Examplefrom mpl_toolkits.mplot3d import axes3d import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_subplot(111, ...

Read More

How can I draw inline line labels in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 16-Jun-2021 3K+ Views

To draw inline labels in Matplotlib, we can use labelLines() method. −StepsSet the figure size and adjust the padding between and around the subplots.Create random data points x using numpy and a list of data points, A.Iterate the list of A, and plot X and a (iterated item) with label.Label all the lines with their respective legends, for lines drawn.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt from labellines import labelLines plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True X = np.linspace(0, 1, 500) A = [1, 2, 5, 10, 20] ...

Read More

How to plot magnitude spectrum in Matplotlib in Python?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 16-Jun-2021 3K+ Views

To plot magintude spectrum, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Get random seed value.Initialize dt for sampling interval and find the sampling frequency.Create random data points for t.To generate noise, get nse, r, cnse and s using numpyCreate a figure and a set of subplots, using subplots() method.Set the title of the plot.Plot the magnitude spectrum.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True np.random.seed(0) dt = 0.01 # sampling interval Fs = ...

Read More

How to plot signal in Matplotlib in Python?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 16-Jun-2021 7K+ Views

To get the signal plot, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Get random seed value.Initialize dt for sampling interval and find the sampling frequency.Create random data points for t.To generate noise, get nse, r, cnse and s using numpy.Create a figure and a set of subplots using subplots() method.Set the title of the plot.Plot t and s data points.Set x and y labels.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True np.random.seed(0) dt ...

Read More

Tweaking axis labels and names orientation for 3D plots in Matplotlib

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 16-Jun-2021 3K+ Views

To tweak axis labels and names orientation for 3D plots in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure with facecolor=white.Get the current figure with 3d projection.Set X, Y and Z Axis labels with linespacing.Plot the data points using plot() method.Set the axis distance.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True figure = plt.figure(facecolor='w') ax = figure.gca(projection='3d') xLabel = ax.set_xlabel('X-axis', linespacing=3.2) yLabel = ax.set_ylabel('Y-axis', linespacing=3.1) zLabel = ax.set_zlabel('Z-Axis', ...

Read More

Plotting scatter points with clover symbols in Matplotlib

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 16-Jun-2021 329 Views

To plot scatter points with clover symbols in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create x, y and z data points using numpy.Plot x, y and s using scatter() method.Set X and Y axes labels.Place a legend at the upper left of the plot.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.arange(0.0, 50.0, 2.0) y = x ** 1.3 + np.random.rand(*x.shape) * 30.0 s = np.random.rand(*x.shape) * 800 + 500 ...

Read More

What's the difference between Matplotlib.pyplot and Matplotlib.figure?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 16-Jun-2021 2K+ Views

matplotlib.pyplotThe matplotlib.pyplot is a collection of functions that make matplotlib work like MATLAB. Each pyplot function makes some change to a figure: e.g., creates a figure, creates a plotting area in a figure, plots some lines in a plotting area, decorates the plot with labels, etc.In matplotlib.pyplot, various states are preserved across function calls, so that it keeps track of things like the current figure and plotting area, and the plotting functions are directed to the current axesmatplotlib.figureThe figure keeps track of all the child Axes, a smattering of 'special' artists (titles, figure legends, etc), and the canvas. A figure ...

Read More

How to pass RGB color values to Python's Matplotlib eventplot?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 16-Jun-2021 2K+ Views

To pass RGB color values to Python's Matplotlib eventplot, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a 1D array, pos, to define the positions of one sequence of eventsMake a list of color tuple r, g, b.Plot identical parallel lines at the given positions.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True pos = 10 * np.random.random(100) colors = [(0.75, 0.50, 0.25)] plt.eventplot(pos, orientation='horizontal',                linelengths=0.75, color=colors) ...

Read More

How to embed fonts in PDFs produced by Matplotlib

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 16-Jun-2021 2K+ Views

To embed fonts in PDFs produced by Matplotlib, we can use rc.Params['pdf.fonttype']=42.StepsSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure, using figure() method.Create x and y data points using numpy.Plot x and y data points using scatter() method.Set the title of the plot.Save the figure in pdf format.Exampleimport numpy as np from matplotlib import pyplot as plt, font_manager as fm plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True plt.rcParams['pdf.fonttype'] = 42 fig, ax = plt.subplots() x = np.random.rand(100) y = np.random.rand(100) ax.scatter(x, y, c=y, marker="v") ...

Read More

How to animate the colorbar in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 16-Jun-2021 2K+ Views

To animate the colorbar in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Add an '~.axes.Axes' to the figure as part of a subplot arrangement.Instantiate Divider based on the pre-existing axes, i.e., ax object and return a new axis locator for the specified cell.Create an axes at the given *position* with the same height (or width) of the main axes.Create random data using numpy.Use imshow() method to plot random data.Set the title of the plot.Instantiate the list of colormaps.To animate the ...

Read More
Showing 41341–41350 of 61,248 articles
Advertisements