How to Change the Background Color in Matplotlib

Change the background color in Matplotlib: a line chart with a light blue figure background and a cream axes background

To change the background color in Matplotlib, set the facecolor: ax.set_facecolor(“lightyellow”) colours the plot area inside the axes, and fig.set_facecolor(“lightblue”) (or plt.figure(facecolor=…)) colours the figure around it. To change the default background color for every plot, set plt.rcParams[“axes.facecolor”] and plt.rcParams[“figure.facecolor”]. This guide covers all of these, plus dark mode with dark_background, transparent PNGs, subplots, the … Read more >>

Matplotlib Scatter Marker: Shape, Size and Color

Matplotlib scatter marker: a reference chart showing every marker style and its code

Three arguments control how a Matplotlib scatter marker looks, and each one does a single job: s is the one that surprises people. It is an area, so s=400 is twice as wide as s=100, not four times. Every chart below is a real Matplotlib window from Python 3.12.5, Matplotlib 3.11.2, NumPy 2.5.3. Every Matplotlib … Read more >>

Matplotlib’s plot_date

plot_date

One of the most useful tools I’ve used for data visualization is Matplotlib. When it comes to plotting time-series data, Matplotlib’s `plot_date` function stands out as an easy yet flexible way to visualize dates on the x-axis. In my experience, handling dates in plots can sometimes be tricky, especially when you want the x-axis to … Read more >>

Matplotlib Log Scale and Log-Log Plots (plt.loglog, semilogx, semilogy)

Matplotlib log scale: the same data plotted with semilogx, semilogy and loglog in real chart windows

Matplotlib sets a log scale with one call: plt.loglog() for both axes, plt.semilogx() or plt.semilogy() for one, or ax.set_xscale("log") on a plot you’ve already drawn: This guide covers log-log plots, power-law fits, the base, zeros, error bars and histograms. The charts are real windows from Python 3.14.7, Matplotlib 3.11.2 and NumPy 2.5.3. Set a log … Read more >>

Matplotlib subplots_adjust

subplots_adjust

One of the libraries I keep coming back to for data visualization is Matplotlib. It’s flexible and widely used across industries in the USA, from finance to healthcare. But if you’ve ever created multiple plots in the same figure, you might have noticed how tricky it can be to get the spacing just right. That’s … Read more >>

Matplotlib Subplots

matplotlib subplot

I’ve worked extensively with data visualization. One library that has always been a go-to is Matplotlib. It’s useful, flexible, and widely used across industries, especially here in the USA, where data-driven decisions are the norm. One feature I often rely on is subplots. They allow you to display multiple plots in a single figure, making … Read more >>

Create a Bar Chart Using Matplotlib in Python

matplotlib bar plot

As a Python developer, I’ve worked extensively with data visualization libraries. Among them, Matplotlib remains one of the most useful and versatile tools for creating a variety of charts, including bar charts. In this article, I’ll walk you through how to create bar charts using Matplotlib. I’ll share practical examples relevant to real-world data, such … Read more >>

How to Draw Horizontal Lines in Matplotlib

matplotlib horizontal line

When I was working with data visualization in Python, plotting horizontal lines in Matplotlib was one of the fundamental skills I needed. In this guide, I’ll share my firsthand experience with several methods to draw horizontal lines in Matplotlib. I’ll keep it simple, practical, and focused on real-world examples relevant to data analysts and developers … Read more >>

How to Draw a Vertical Line in Matplotlib?

matplotlib vertical line

As a Python developer with over a decade of experience, I’ve found Matplotlib to be an invaluable tool for data visualization. In this guide, I’ll walk you through simple and practical ways to draw vertical lines in Matplotlib. The methods I share come from real-world experience, designed to help you quickly add vertical markers to … Read more >>

Create and Customize Dashed Lines in Matplotlib

matplotlib dashed line spacing

As a developer, I’ve worked extensively with Matplotlib for data visualization. One of the most common yet useful ways to enhance your plots is by using dashed lines. In this article, I’ll walk you through everything you need to know about creating and customizing dashed lines in Matplotlib. I’ll share practical tips and different methods … Read more >>