Reputation: 19243
I have vales with very small difference like... 0.000001. I want to visualize them on logarithmic scale. I am wondering how to do it in matplotlib.
Thanks a lot
Upvotes: 7
Views: 36192
Reputation: 26530
Since all other answers only mention the global pyplot.xscale("log")
approach: You can also set it per axis, but then the syntax is:
ax.set_yscale("log")
Upvotes: 3
Reputation: 2670
http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.axis
Simply add the keyword argument log=True
Or, in an example:
from matplotlib import pyplot
import math
pyplot.plot([x for x in range(100)],[math.exp(y) for y in range(100)] )
pyplot.xlabel('arbitrary')
pyplot.ylabel('arbitrary')
pyplot.title('arbitrary')
#pyplot.xscale('log')
pyplot.yscale('log')
pyplot.show()
Upvotes: 18
Reputation: 20196
Instead of plot
, you can use semilogy
:
import numpy as npy
import matplotlib.pyplot as plt
x=npy.array([i/100. for i in range(100)])
y=npy.exp(20*x)
plt.semilogy(x, y)
plt.show()
But I'm not entirely sure what you hope to gain from using a log scale. When you say "small difference", do you mean that the values might be something like 193.000001 and 193.000002? If so, it might help to subtract off 193.
Upvotes: 2
Reputation: 4448
You can use this piece of code:
import matplotlib.pyplot
# to set x-axis to logscale
matplotlib.pyplot.xscale('log')
# to set y-axis to logscale
matplotlib.pyplot.yscale('log')
Upvotes: 2