我刚刚开始学习matplotlib,并希望有4个子图(2x2),其y轴标签用美元符号和逗号进行格式化。
我查看了this post和this 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