Sarah
Sarah

Reputation: 617

How can I change y ticks using matplotlib?

I have subplots, I want to change y ticks of only one plot from 0.1 to 10, therefore multiplying 10 to each y ticks. I tried to set using set_yticks([0, 10, 20, ..]) but somehow all the numbers get squished to the top. Is there any way?

enter image description here

Upvotes: 2

Views: 1271

Answers (1)

William Miller
William Miller

Reputation: 10328

You're looking for matplotlib.axes.Axes.set_yticklabels, this will leave the tick marks where they are but change the labels. Example usage:

import matplotlib.pyplot as plt
import numpy as np

fig, axs = plt.subplots(1, 2, figsize=(12,6))
axs[0].set_yticklabels(np.linspace(0, 6, len(axs[0].get_yticks())))
plt.show()

enter image description here

Upvotes: 1

Related Questions