简体   繁体   English

Matplotlib:如何避免 x 轴上的“0”

[英]Matplotlib:How to avoid '0' on the x axis

I'm using this code to plot a bar chart:我正在使用此代码来 plot 条形图:

plt.figure(figsize=(8, 6))
plt.subplot(211)
for i in instance.J:
    plt.bar(i, value(instance.P[i]))
plt.xlabel('Generators',fontweight='bold')
plt.ylabel('Power (MW)',fontweight='bold')
plt.xlim(xmin=0)
plt.xticks(range(55),rotation=90,size=9)
plt.title('Power dispatch')

The result is shown below.结果如下所示。 How to avoid 0 on the x-axis?如何避免x轴为0
Anyone can help me with this problem?任何人都可以帮我解决这个问题吗?

在此处输入图像描述

You can try replacing the tick label at 0 with '' like this:您可以尝试将0处的刻度 label 替换为''如下所示:

plt.xticks(range(55), [a if a else '' for a in range(55)])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM