美元刻度#

使用格式字符串在 y 轴标签上添加美元符号.

import matplotlib.pyplot as plt
import numpy as np

# Fixing random state for reproducibility
np.random.seed(19680801)

fig, ax = plt.subplots()
ax.plot(100*np.random.rand(20))

# Use automatic StrMethodFormatter
ax.yaxis.set_major_formatter('${x:1.2f}')

ax.yaxis.set_tick_params(which='major', labelcolor='green',
                         labelleft=False, labelright=True)

plt.show()
dollar ticks

参考

以下函数,方法,类和模块的用法在本例中显示:

  • matplotlib.pyplot.subplots

  • matplotlib.axis.Axis.set_major_formatter

  • matplotlib.axis.Axis.set_tick_params

  • matplotlib.axis.Tick

  • matplotlib.ticker.StrMethodFormatter

Gallery generated by Sphinx-Gallery