Practical solutions

Python Matplotlib Howto's How-To Guides

Solve the problem. Keep building. Collection of Python Matplotlib how-to articles

Find the answer you need

Browse practical solutions, grouped by the task you're working on.

__COUNT__ entries on this page

LaTeX Formulas in MatplotlibThis tutorial explains how to render LaTeX formulas and equations in Matplotlib. Learn to create professional visualizations with LaTeX-enhanced titles, labels, and annotations. Discover methods to customize text rendering and enhance your plots with mathematical clarity. Perfect for scientists and engineers looking to elevate their work. How to Make a Square Plot With Equal Axes in MatplotlibWe can use set_aspect() method and axis() method to make a square plot with equal axes in Matplotlib. How to Display an Image in Grayscale in MatplotlibThis article introduces how to display a grayscale image in Matplotlib. Matplotlib TriangulationThis post will help you to understand the Matplotlib triangulation. How to Save Plots as PDF File in MatplotlibLearn how to save plots as PDF files in Matplotlib using the savefig() function and PdfPages class. This guide covers saving single and multiple plots, along with customization options to enhance your visualizations. Perfect for reports and presentations! How to Set Tick Label in Scientific Notation in MatplotlibThis article teaches you how to set tick labels in scientific notation using Matplotlib in Python. Learn about the `ticklabel_format()` function, `ScalarFormatter`, and `FuncFormatter` to enhance your data visualizations. Perfect for beginners and experienced users alike, this guide provides clear examples and explanations to help you create professional-looking graphs. Differences Between cla(), clf(), and close() Functions in MatplotlibCompare the Matplotlib pyplot functions cla(), clf(), and close(): cla() clears the current Axes, clf() clears the current Figure, and close() closes a Figure managed by pyplot. Visible-window behavior depends on the backend and execution context. How to Add Text Inside the Plot in MatplotlibLearn how to use matplotlib.pyplot.text() to place labels at data coordinates, set axis limits, customize text, and add annotations or multi-line notes to Matplotlib plots. How to Create Density Plot in MatplotlibEstimate a density function from sample data with gaussian_kde() from scipy.stats and draw it with Matplotlib, or use kdeplot() from seaborn and kind='density' in pandas.DataFrame.plot(). How to Add a Y-Axis Label to the Secondary Y-Axis in MatplotlibLearn how to add a y-axis label to the secondary y-axis in Matplotlib using the axes object and pandas DataFrame plot method. This guide provides step-by-step instructions, code examples, and tips for customizing your visualizations. Perfect for data analysts and anyone interested in enhancing their data visualization skills. How to Plot Histogram for List of Data in MatplotlibPlot a histogram from a Python list with Matplotlib's plt.hist(), then adjust its bins, density, and color. How to Convert a NumPy Array to PIL Image in PythonConvert NumPy arrays to Pillow images with Image.fromarray(). Learn how array shape, dtype, and value range affect grayscale, RGB, and Matplotlib-colormapped images, then resize and save the result. How to Create a Surface Plot in MatplotlibLearn how to create a Matplotlib 3D surface plot from grid-shaped data, then customize its colors, view, and saved figure. How to Plot Logarithmic Axes in MatplotlibPlot logarithmic axes in Matplotlib with set_yscale(), semilogy(), or loglog(). How to Plot a Circle in MatplotlibDraw a circle in Matplotlib with a Circle patch, its equation, or a scatter marker. How to Connect Scatterplot Points With Line in MatplotlibConnect Matplotlib scatterplot points in data order with plot(), style the line, and control which layer appears on top with zorder. How to Add Title to Subplots in MatplotlibWe can add a title to subplots in Matplotlib using Axes.set_title(), Axes.title.set_text(), or pyplot's current axes (plt.gca()). How to Create a Single Legend for All Subplots in MatplotlibLearn how to create a single legend for all subplots in Matplotlib with our comprehensive guide. Discover effective methods like using fig.legend(), customizing legend placement, and creating legends from multiple handles. Enhance your data visualizations and improve clarity with these techniques. How to Plot Two Histograms Together in MatplotlibPlot two histograms together in Matplotlib using grouped bars, transparent overlays, or separate subplots. Compare datasets with shared bins, labels, and styles. How to Rotate X-Axis Tick Label Text in MatplotlibLearn five ways to rotate Matplotlib x-axis tick labels and align them when long labels overlap. How to Plot Horizontal and Vertical Line in MatplotlibThis tutorial introduces how to plot horizontal and vertical lines in Matplotlib with axhline and axvline, hlines and vlines, and the axhspan and axvspan shading functions. How to Show Pyplot Grid in MatplotlibAdd a grid to a Matplotlib plot with grid(), customize its color and line style, and choose vertical or horizontal grid lines. How to Display an Image With Matplotlib PythonLearn how to load and display a local image with Matplotlib's imshow(), display a PIL image, customize its appearance, and save the figure. How to Plot Smooth Curve in MatplotlibThis tutorial explains how we can plot a smooth curve from given coordinates using the modules from the scipy and matplotlib package.