Change Tick Frequency in Matplotlib

python_tutorials

Introduction

Matplotlib is one of the most widely used data visualization libraries in Python. Much of Matplotlib’s popularity comes from its customization options – you can tweak just about any element from its hierarchy of objects.

In this tutorial, we’ll take a look at how to change the tick frequency in Matplotlib. We’ll do this on the figure-level as well as the axis-level.

How to Change Tick Frequency in Matplotlib?

Let’s start off with a simple plot. We’ll plot two lines, with random values:

import matplotlib.pyplot as plt
import numpy as np

fig = plt.subplots(figsize=(12, 6))

x = np.random.randint(low=0, high=50, size=100)
y = np.random.randint(low=0, high=50, size=100)

plt.plot(x, color='blue')
plt.plot(y, color='black')

plt.show()

x and y range from 0-50, and the length of these arrays is 100. This means, we’ll have 100 datapoints for each of them. Then, we just plot this data onto the Axes object

 

 

To finish reading, please visit source site