Transforming Your Matplotlib Plots to Traditional Style

Your Dose of Scientific Python

Mathcube
3 min readApr 24, 2023
Photo by John Cameron on Unsplash

Matplotlib is a powerful library that enables users to quickly create production-ready plots with ease. However, it has certain opinions on how a plot should appear by default. While it’s always possible to customize these plots, it can sometimes be challenging to achieve the desired result. One common issue encountered is the default positioning of the axes at the borders of the plot. If you prefer a more traditional layout with the origin in the center and the axes passing through the origin, as well as arrows at the ends of the axes, some adjustments need to be made.

Daily Dose of Scientific Python

106 stories

In the context of Matplotlib, what we typically refer to as an “axis” is called a “spine.” To achieve the desired appearance, we must manipulate the Spine objects. The primary tasks are to disable the left and top spines, and move the right and bottom spines to the origin. Afterward, we can plot the arrowheads. Here’s one method for achieving this:

import matplotlib.pyplot as plt
import numpy as np

fig, ax =…

--

--