Python SciPy IIR Filter: Design, Plot and Apply

Python SciPy IIR filter: Matplotlib plot of a noisy 4 Hz sensor signal smoothed by a 20 Hz low-pass filter

If you need to strip 60 Hz hum and noise from a sensor reading, design the filter with scipy.signal.iirfilter(…, output=”sos”) and apply it with sosfiltfilt(). That’s a Python SciPy IIR filter in two lines, and it won’t shift your signal in time. People get stuck on the details: which type, what order, and why the … Read more >>

Overlay Two Bar Charts in Matplotlib with Python

Overlay two bar charts in Matplotlib: narrow actual sales bars drawn in front of wider target bars

My sales manager friend asked for one chart: each month’s target and actual sales in the same spot, so a miss jumps out. To overlay two bar charts in Matplotlib, call ax.bar() twice with the same x positions and make the front series narrower: Here’s what we’re building, a target-vs-actual chart where green bars hit … Read more >>

Add Multiple Bar Chart Labels in Matplotlib with Python

Matplotlib multiple bar chart labels: grouped bars with dollar values on top and percentage shares inside

Many guides still label a grouped bar chart with a hand-written ax.text() loop. It works, but you do x-position math for every bar. For Matplotlib multiple bar chart labels, the better answer is ax.bar_label(), called once for each group of bars you draw: In this tutorial, I’ll show you how to add Matplotlib multiple bar … Read more >>

Customize Matplotlib Scatter Plot Legend Facecolor in Python

Matplotlib scatter plot legend facecolor: Austin listings scatter with a light yellow legend box

A real-estate client wanted the Matplotlib scatter plot legend facecolor solid so it stood out from the colored points. The answer is ax.legend(facecolor=…, framealpha=1). Their first try only passed facecolor, and the box still looked washed out. That’s because Matplotlib draws it at 80% opacity. Quick answer: set color and opacity together: In this tutorial, … Read more >>

How to Save Images in Python (Pillow, OpenCV, Matplotlib)

Save images in Python: a Matplotlib sales chart saved with savefig() and shown in its plot window

Pillow’s Image.save() is the call most people need when they want to save images in Python: pass a file name and the extension (.png, .jpg, .webp) picks the format. Charts use Matplotlib’s savefig(), and NumPy arrays use OpenCV’s cv2.imwrite(): My test machine for this page ran Windows 11 with Python 3.12.5, Pillow 12.3.0, Matplotlib 3.11.2, … Read more >>

How to Build a JPG to PNG Converter Using Python

How to Build a JPG to PNG Converter Using Python

When I need to convert a batch of JPG images, opening each file and saving it manually quickly becomes repetitive. A small Python application makes this much easier, especially when you need to process several images at once. For this project, I built a JPG to PNG Converter using Python with Streamlit for the interface … Read more >>

How to Save a Matplotlib Graph as PNG in Python

Matplotlib bar chart of 2026 monthly coffee shop revenue, saved as a PNG file with savefig

A chart stuck in a pop-up window can’t go in a report. To save a Matplotlib graph as PNG, call savefig() with a .png filename before plt.show(). In this tutorial, we’ll cover the matplotlib save graph as png workflow from one file to a whole folder, including resolution, clipped legends and saving without a window. … Read more >>

Display Images in Matplotlib Subplots with Custom Sizes

Display images in Matplotlib subplots: a two by two grid of four city images of different sizes shown with imshow

If you’ve tried putting photos in a subplot grid, you’ve probably seen tiny pictures floating in huge white gaps. In this tutorial, I’ll display images in Matplotlib subplots with imshow() on each axes, then size them with figsize and width_ratios. Those gaps appear because imshow() protects the picture’s shape, so a wide photo can’t fill … Read more >>

How to Install a Module in Python (pip Guide)

How to install a module in Python: Command Prompt showing ModuleNotFoundError, pip install, and the module working

Here’s how to install a module in Python: run python -m pip install followed by the package name, ideally inside a virtual environment. Then import it in your code: I ran every command below in a fresh virtual environment with Python 3.12.5 on Windows, so the output is exactly what pip printed. We’ll go from … Read more >>