如何使用pandas和Matplotlib图显示以百万计的Y值,以及如何显示三个变量图?

时间:2019-05-12 13:52:40

标签: python pandas matplotlib

enter image description here

我是否可以编辑此代码以在y轴上显示20.4m并绘制三个变量图?

#设置

的位置和宽度

我是否可以沿Y轴显示20.7m,并在此代码中显示三个变量图?


标题

  

Blockquote

酒吧     pos = list(range(len(df ['IGR2011'])))     宽度= .20

# Plotting the bars
fig, ax = plt.subplots(figsize=(15,8))

# Create a bar with pre_score data,
# in position pos,
plt.bar(pos, 
        #using df['pre_score'] data,
        df['IGR2011'], 
        # of width
        width, 
        # with alpha 0.5
        alpha=0.5, 
        # with color
        color='#EE3224', 
        # with label the first value in first_name
        label=df['STATE'][0]) 

# Create a bar with mid_score data,
# in position pos + some width buffer,
plt.bar([p + width for p in pos], 
        #using df['IGR2017'] data,
        df['IGR2017'],
        # of width
        width, 
        # with alpha 0.5
        alpha=1, 
        # with color
        color='#F78F1E', 
        # with label the second value in first_name
        label=df['STATE'][1]) 

# Create a bar with post_score data, in position pos + some width     buffer,
plt.bar([p + width*2 for p in pos], 
        #using df['INCREMENT'] data,
        df['INCREMENT'], 
        # of width
        width, 
        # with alpha 0.5
        alpha=1, 
        # with color
        color='#FFC222', 
        # with label the third value in first_name
        label=df['STATE'][4]) 

# Set the y axis label
ax.set_ylabel('IGR')

# Set the chart's title
ax.set_title('Performance of Outgoing State Govs 2011 - 2017')

# Set the position of the x ticks
ax.set_xticks([p + 1.5 * width for p in pos])

# Set the labels for the x ticks
ax.set_xticklabels(df['STATE'])

# Setting the x-axis and y-axis limits
plt.xlim(min(pos) - width, max(pos) + width *5)
plt.ylim([0, max(df['IGR2011'] + df['INCREMENT'] + df['IGR2017'])] )


# Adding the legend and showing the plot
plt.legend(['IGR2011', 'IGR2017', 'INCREMENT'], loc='upper left')
plt.grid()
plt.show()

0 个答案:

没有答案