Giovanni Soldi
Giovanni Soldi

Reputation: 405

Vary the scale of x-axis with Matplotlib

I would like to know if there is a practical way to vary the scale of an axis with matplotlib. More precisely, larger scale for small numbers and smaller scale for large numbers. I have the following code snippet:

x = [0,15,546,6076,10694,12000]
x = [float(y)/100 for y in x]
y = [0,0,1,2,3,4] 
plt.step(x, y)

plt.xlim([0, 150])
plt.ylim([0,10])    
plt.xticks(x,rotation='vertical')
plt.yticks(y)

plt.show()

And the resulting graph is the following: enter image description here

Basically, the 0 and 0.1 label overlaps so I would like a larger scale for small numbers and smaller scale for large numbers.

Thank you very much in advance for the help!

Cheers, Giovanni

Upvotes: 1

Views: 811

Answers (1)

challett
challett

Reputation: 906

You may want to look into using a logarithmic scale for your graph. It may solve your issue. You can do this by adding:

plt.yscale('log')
plt.xscale('log')

To your code before plt.show()

Upvotes: 2

Related Questions