【发布时间】:2015-06-04 16:08:17
【问题描述】:
如果我绘制对数比例图,matplotlib 会给我漂亮的条目 105、106、...
为了可读性,我更喜欢 1e5, 1e6, ...
我可以直接将轴属性设置为这样吗?
我相当丑陋的黑客会是:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(1, 40, 100);
y = np.linspace(1, 5, 100);
# Actually plot the exponential values
plt.plot(x, 10**y)
ax = plt.gca()
ax.set_yscale('log')
# Rewrite the y labels
y_labels = ax.get_yticks()
ax.set_yticklabels(['1e%i' % np.round(np.log(y)/np.log(10)) for y in y_labels])
plt.show()
但肯定有更好的方法。
【问题讨论】:
-
ticker和FormatStrFormatter可能有某种方式