Skip to content Skip to sidebar Skip to footer

Override Y Axis Tick Labels Without Affecting The Graph Shape In Pyplot

what I want to manually override the y axis tick labels without affecting the original plot. For example, how I can show y axis tick labels [1,10,100,1000,10000] instead without af

Solution 1:

set_yticklabels is the method of Axes instance, and is not present in the pylab interface. Try instead

pl.gca().set_yticklabels(newYlabel)

gca here stands for get current axes.

EDIT: The picture: enter image description here

The script that was used to obtain it:

import numpy as np
import pylab as pl
x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]
pl.plot(x, y)
pl.title('Plot of y vs. x')
pl.xlabel('x axis')
pl.ylabel('y axis')
newYlabel = ['1','10','100','1000','10000']
pl.gca().set_yticklabels(newYlabel)
pl.show()

Used matplotlib 1.4.3 with python 2.7.8 on Fedora 21.


Post a Comment for "Override Y Axis Tick Labels Without Affecting The Graph Shape In Pyplot"