Search code examples
pythonmatplotlibpyomoxticks

Matplotlib:How to avoid '0' on the x axis


I'm using this code to plot a bar chart:

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?
Anyone can help me with this problem?

enter image description here


Solution

  • You can try replacing the tick label at 0 with '' like this:

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