如何在matplotlib

时间:2019-07-17 02:40:51

标签: python matplotlib data-visualization

我已经设法使用matplotlib绘制聚类的条形图,但是我面临的问题是,与其他图形相比,有些图形太小了,而用matplotlib绘制时,它们似乎不存在。是否有可能改变y轴,或者是否有任何方法可以使较小的条形图看起来更清晰?

这是我的可视化代码。

# Setting the positions and width for the bars
pos = list(range(len(df3['Air']))) 
width = 0.25 

# Plotting the bars
fig, ax = plt.subplots(figsize=(10,5))

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

# Create a bar with mid_score data,
# in position pos + some width buffer,
plt.bar([p + width for p in pos], 
        #using df['mid_score'] data,
        df3['Land'],
        # of width
        width, 
        # with alpha 0.5
        alpha=0.5, 
        # with color
        color='#F78F1E', 
        # with label the second value in first_name
        label=df3['Region'][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['post_score'] data,
        df3['Sea'], 
        # of width
        width, 
        # with alpha 0.5
        alpha=0.5, 
        # with color
        color='#FFC222', 
        # with label the third value in first_name
        label=df3['Region'][2]) 

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

# Set the chart's title
ax.set_title('Total arrival count by mode of transport by region in 2014')

# 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(df3['Region'])

# Setting the x-axis and y-axis limits
plt.xlim(min(pos)-width, max(pos)+width*4)
plt.ylim([0, max(df3['Air'] + df3['Land'] + df3['Sea'])] )

# Adding the legend and showing the plot
plt.legend(['Air', 'Land', 'Sea'], loc='upper left')
plt.grid()
plt.show()

这是我的图表。如您所见,大多数图形都看不到。

This is the graph that I have. As you can observe, most graphs cannot be seen.

1 个答案:

答案 0 :(得分:1)

尝试使用log scale

plt.yscale('log')

plt.bar([p + width*2 for p in pos],
    ....)