Member-only story
How to Customize Matplotlib Plots with Tick Locators
Having full control over a data visualization is a great feature.
Very few people would argue if I say Matplotlib is the mother of Python data visualization libraries. It is one of the first libraries I learned about along with Pandas.
I think the strength of Matplotlib is the flexibility it offers. You can customize pretty much anything on a plot. This requires writing additional lines of codes but it is a reasonable trade-off to achieve full control over a visualization.
In this article, we will learn different ways of customizing the ticks on the x-axis and y-axis of a plot. The default output usually works well but there will be cases where a customization is necessary.
We will be using the ticker and dates modules of Matplotlib. Let’s start with creating a sample DataFrame for the examples.
import numpy as np
import pandas as pddf = pd.DataFrame(
{"price": np.random.randn(1000) + 10},
index=pd.date_range(start="2022-01-01", periods=1000, freq="D"))df = df.resample("10D").mean()df.head()