У меня есть столбчатая диаграмма с двумя столбцами.Я хотел бы отформатировать его так, чтобы вторая полоса была зеленой и чтобы значения «на графике» были отформатированы как $ x, 000 («$ {x:,. 0f}»).
Ниже приведен мойобразец кода.Можете ли вы помочь?
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc
import matplotlib as mpl
wd_cur_annual = 500
wd_best_annual_0 = 340
font = {'family' : 'arial',
'weight' : 'normal',
'size' : 14}
plt.rc('font', **font)
x = [0,1]
y = [(wd_cur_annual),(wd_best_annual_0)]
width = 0.8 # width of the bars
fig, ax = plt.subplots()
rects1 = ax.bar(x, y, width, color='r')
ax.set_ylim(0,(wd_cur_annual*1.1))
ax.set_ylabel('Annual cost')
ax.set_title('Recommendation')
ax.set_xticks(np.add(x,(width/2))) # set the position of the x ticks
ax.set_xticklabels(('Current plan', 'Recommended plan'))
ax.yaxis.set_major_formatter(mpl.ticker.StrMethodFormatter('${x:,.0f}'))
def autolabel(rects):
# attach some text labels
for rect in rects:
height = rect.get_height()
ax.text(rect.get_x() + rect.get_width()/2., .5*height,
'%d' % int(height),
ha='center', va='bottom')
autolabel(rects1)
plt.show()