问题
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
回答1:
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()
回答2:
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")
回答3:
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')
回答4:
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.
来源:https://stackoverflow.com/questions/9979378/how-to-visualize-values-on-logarithmic-scale-on-matplotalib