Home > Blockchain >  matplotlib how do I reduce the amount of space between bars in a stacked bar chart when x-axis are d
matplotlib how do I reduce the amount of space between bars in a stacked bar chart when x-axis are d

Time:07-14

import pandas as pd
from datetime import datetime
import matplotlib.pyplot as plt
import numpy as np
x=pd.date_range(end=datetime.today(),periods=150,freq='W').to_pydatetime().tolist()
x_1 = np.random.rand(150)
x_2 = np.random.rand(150)/2
fig = plt.figure(figsize=(10,6),dpi=100)
ax=fig.add_subplot(111)
ax.bar(x,x_1,label='x_1')
ax.bar(x,x_2,label='x_2',bottom=x_1)
plt.legend()
plt.show()

The above code will provide this stacked bar chart.

enter image description here

  • Related