Matplotlib is hiring a Research Software Engineering Fellow! See discourse for details. Apply by January 3, 2020
使用A FormatStrFormatter
在Y轴标签上预先加上美元符号。
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
# Fixing random state for reproducibility
np.random.seed(19680801)
fig, ax = plt.subplots()
ax.plot(100*np.random.rand(20))
formatter = ticker.FormatStrFormatter('$%1.2f')
ax.yaxis.set_major_formatter(formatter)
for tick in ax.yaxis.get_major_ticks():
tick.label1On = False
tick.label2On = True
tick.label2.set_color('green')
plt.show()
以下函数、方法、类和模块的使用如本例所示: