Save 3D Plot in PDF with Python

Rishikesh Kumar Rishi
Updated on 09-Oct-2021 09:38:47

5K+ Views

To save a 3D-plot in a PDF with Python, 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.Create u, v, x, y and z data points using numpy.Plot a 3D wireframe.Set the title of the plot.Save the current figure using savefig() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_subplot(111, projection='3d') u, v = np.mgrid[0:2 * np.pi:30j, ... Read More

Control the Border of a Bar Patch in Matplotlib

Rishikesh Kumar Rishi
Updated on 09-Oct-2021 09:35:09

6K+ Views

To control the border of a bar patch in matplotlib, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a list of heights and a tuple for labels.Use the bar() method with edgecolor in the argument to control the color of the bar patch. Here we have used edgecolor='green'.Set the ticks and labels of the X-axis.To display the figure, use Show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True height = [3, 12, 5, 18, 45] labels = ('P1', 'P2', 'P3', 'P4', ... Read More

Plot Two Different Spaced Time Series on One Plot in Python Matplotlib

Rishikesh Kumar Rishi
Updated on 09-Oct-2021 09:31:18

3K+ Views

To plot two different spaced time series on one same plot using Matplotlib, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create x1, y1 and x2 and y2 data points.Create a figure and a set of subplots.Plot the data that contains dates, with (x1, y1) and (x2, y2) data points.Set the major formatter of the X-axis ticklabels.Rotate xtick label by 45 degrees using tick_params() method.To display the figure, use Show() method.Exampleimport matplotlib.pyplot as plt from matplotlib.dates import date2num, DateFormatter import datetime as dt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True ... Read More

Change Bar Chart Values to Percentages in Matplotlib

Rishikesh Kumar Rishi
Updated on 09-Oct-2021 09:29:06

10K+ Views

To change bar chart values to percentage in matplotlib, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Make a list of frequencies.Create a new figure or activate an existing figure.Make a bar plot using bar() method.Iterate the bar plot and find the height of each patch and use annotate() method to put values in percentages.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 frequencies = [7, 8, 5, 3, 6] plt.figure() p1 = ... Read More

Increase Colormap Linewidth Quality in Streamplot Matplotlib

Rishikesh Kumar Rishi
Updated on 09-Oct-2021 09:27:08

329 Views

To increase colormap/linewidth quality in streamplot matplotlib, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Create x and y data points and then use np.meshgrid() to return the coordinate matrices from the coordinate vectors.Find X and Y using x and y data points.Create a streamplot with x, y, X and Y data points. You can increase the linewidth using the linewidth parameter in the method. Here we have used linewidth=5.Create a colorbar for a ScalarMappable instance, *stream.lines*.To display the figure, use Show() method.Exampleimport numpy ... Read More

Change Transparency of a Matplotlib Table

Rishikesh Kumar Rishi
Updated on 09-Oct-2021 09:23:22

616 Views

To change the transparency/opaqueness of a matplotlib table, we can atke following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Create a random dataset with 10×3 dimension.Create a tuple of columns.Get rid of the axis markers using axis('off').Create a table with data and columns.Iterate each cell of the table and change its transparency/opaqueness using set_alpha() 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 fig, axs = plt.subplots(1, 1) data = np.random.random((10, 3)) ... Read More

Embedding Matplotlib Animation into a Tkinter Frame

Rishikesh Kumar Rishi
Updated on 09-Oct-2021 09:15:07

5K+ Views

To embed a matplotlib animation into a tkinter frame, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a Toplevel widget of Tk which represents mostly the main window of an applicationSet the title of this widget.Add an axes to the current figure and make it the current axes.Create a new figure or activate an existing figure.Add an 'ax' to the figure as part of a subplot arrangement.Make a dummy line plot with linewidth=2.Create the canvas the figure renders into.Create the figure canvas on which to operate.Create a keypress event to ... Read More

Save Multiple Figures to One PDF File in Matplotlib

Rishikesh Kumar Rishi
Updated on 09-Oct-2021 09:06:44

5K+ Views

To save multiple figures in one PDF file at once, we can take follwong stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a new figure (fig1) or activate and existing figure using figure() method.Plot the first line using plot() method.Create another figure (fig2) or activate and existing figure using figure() method.Plot the second line using plot() method.Initialize a variable, filename, to make a pdf file.Create a user-defined function save_multi_image() to save multiple images in a PDF file.Call the save_multi_image() function with filename.Create a new PdfPages object.Get the number of open figures.Iterate the opened figures and ... Read More

Show NumPy 2D Array as Grayscale Image in Jupyter Notebook

Rishikesh Kumar Rishi
Updated on 09-Oct-2021 08:57:15

5K+ Views

To show a 2D array as a grayscale image in Jupyter Notebook, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a random data using numpy.Display the data as an image, i.e., on a 2D regular raster, with gray colormap.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.00, 3.50] plt.rcParams["figure.autolayout"] = True # Random data points data = np.random.rand(5, 5) # Plot the data using imshow with gray colormap plt.imshow(data, cmap='gray') # ... Read More

Filling the Region Between a Curve and X-Axis in Python Using Matplotlib

Rishikesh Kumar Rishi
Updated on 09-Oct-2021 08:55:24

2K+ Views

To fill the region between a curve and X-axis in Python using Matplotlib, we can take the following stepsStepsSet 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.Fill the area between the curve and the X-axis using fill_between() method.To display the figure, use Show() method.Exampleimport matplotlib.pyplot as plt import numpy as np # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create x and y data points x = np.linspace(-5, 5, 100) y = np.sin(x) ... Read More

Advertisements