使用带有美元符号刻度标签的MatPlotLib的子图 - 如何格式化

时间:2017-12-23 17:23:18

标签: matplotlib display comma subplot dollar-sign

我刚刚开始学习matplotlib,并希望有4个子图(2x2),其y轴标签用美元符号和逗号进行格式化。

我查看了this postthis post,并编写了以下代码

import numpy as np  
import pandas as pd 
import matplotlib.pyplot as plt  
import matplotlib.ticker as mtick

x = [i*100 for i in range(10)]
y = [i*1000 for i in range(10)]
f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, sharex='col', sharey='row')
plt.ylim(0,15000)

fmt = '${x:,.0f}'
tick = mtick.StrMethodFormatter(fmt)
ax.yaxis.set_major_formatter(tick)

ax1.scatter(x,y, color='r')
ax2.scatter(x,y, color='r')
ax3.scatter(x, y , color='r')
ax4.scatter(x, y, color='r')
ax1.set_title('Sharing x per column, y per row')
plt.show()

但是我获得的图表有不同的y轴标签,它们都没有美元符号或逗号,如下所示: 2 x 2 subplots without proper y labels

0 个答案:

没有答案