简体   繁体   English

Python - matplotlib修改xticks的“loglog”图

[英]Python - matplotlib modify xticks for a “loglog” plot

I am plotting in log scale for each axis, but I don't want scientific notation for the x axis, so I modified it as follows: 我正在绘制每个轴的对数刻度,但我不想要x轴的科学记数法,所以我修改它如下:

from matplotlib import pyplot as plt
from matplotlib.ticker import FormatStrFormatter

a = np.array([10.**(-2), 10.**(-3), 5.*10**(-3),10.**(-4), 10.**(-6), 10.**(-7)])
b = np.array([16, 12.5, 14.5, 9.5, 8., 7.5])

axes = plt.subplot(111)

plt.loglog(a,b, 'k.',markersize=10,markerfacecolor='None',label='')

plt.ylim(10**(-6),10**(-1))
plt.xlim(5,30)
plt.subplots_adjust(left=0.15)
plt.legend(loc=2)
axes.xaxis.set_minor_formatter(FormatStrFormatter("%.0f"))
plt.show()

But, as you can see in the picture below, there is 10 in scientific notation amongst the x axis labels... I don't know how to suppress it and just have 10 ... 但是,正如你在下面的图片中看到的那样,x轴标签中有10个科学记数法......我不知道如何压制它,只有10 ......

在此输入图像描述

You can use the ScalarFormatter from matplotlib.ticker 您可以使用matplotlib.tickerScalarFormatter

import matplotlib.pyplot as plt
from matplotlib.ticker import ScalarFormatter

fig = plt.figure()
ax = fig.add_subplot(111)
ax.semilogx(range(100))
ax.set_xscale('log')
ax.set_yscale('log')
ax.xaxis.set_major_formatter(ScalarFormatter())
#ax.yaxis.set_major_formatter(ScalarFormatter()) # for the y axis

fig.show()

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM