如何控制 matplotlib 中的轴标签?
How to control axis labels in matplotlib?
我正在尝试使用 matplotlib 将一些数据可视化为散点图,我得到了以下信息:
有没有办法强制y轴显示以下步骤[0,10,100,1000,10000,...]
类似于以下内容:
如果你是直接使用matplotlib
并且对新式格式字符串比较熟悉的话,你可以试试这个:
from matplotlib.ticker import StrMethodFormatter
plt.figure()
plt.ylim(10e1,10e6)
plt.yscale('log')
plt.gca().yaxis.set_major_formatter(StrMethodFormatter('{x:,.2f}')) # 2 decimal places
plt.grid()
class matplotlib.ticker.StrMethodFormatter(fmt)
Use a new-style format string (as used by str.format()) to format the
tick.
The field used for the value must be labeled x and the field used for
the position must be labeled pos.
输出图像:
答案是将 yscale()
设置为 'log' 我得到了非常好的结果:
我正在尝试使用 matplotlib 将一些数据可视化为散点图,我得到了以下信息:
有没有办法强制y轴显示以下步骤[0,10,100,1000,10000,...]
类似于以下内容:
如果你是直接使用matplotlib
并且对新式格式字符串比较熟悉的话,你可以试试这个:
from matplotlib.ticker import StrMethodFormatter
plt.figure()
plt.ylim(10e1,10e6)
plt.yscale('log')
plt.gca().yaxis.set_major_formatter(StrMethodFormatter('{x:,.2f}')) # 2 decimal places
plt.grid()
class matplotlib.ticker.StrMethodFormatter(fmt)
Use a new-style format string (as used by str.format()) to format the tick.
The field used for the value must be labeled x and the field used for the position must be labeled pos.
输出图像:
答案是将 yscale()
设置为 'log' 我得到了非常好的结果: