0

Am just starting to learn matplotlib and want to have 4 subplots (2x2) that have y axis labels formatted with dollar signs and commas.

I have looked at this post and this post and wrote the following code

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()

But the plots that I get have different y axis labels and neither of them have dollar signs or commas as seen here: 2 x 2 subplots without proper y labels

MVigoda
  • 93
  • 1
  • 6
  • You use `ax` but never define it. This should trigger an error without any plot being produced. Appart the method shown in [the linked question](https://stackoverflow.com/questions/38152356/matplotlib-dollar-sign-with-thousands-comma-tick-labels) works as expected. – ImportanceOfBeingErnest Dec 23 '17 at 17:43
  • I appreciate the comment, but I did reference the other question in my posting, but I still have the issue. Would you mind spelling out the answer in a bit more detail? – MVigoda Dec 23 '17 at 18:06
  • The variable `ax` is not defined. If you set the formatter for an axes which is not defined, it will not work. – ImportanceOfBeingErnest Dec 23 '17 at 18:11

0 Answers0