I have a plot in Matplotlib and I would like to increase the margins between the ticks on the x-axis by increasing the widht of the diagram. I tried to use the code mentioned here
plt.figure(figsize=(20,10))
--> did not seem to have any effect
fig, ax = plt.subplots(figsize=(20, 10))
--> created a diagram with an empty plot
Here is my code :
from matplotlib import pyplot as plt
from scipy.interpolate import interp1d
import numpy as np
load = [0.0, 0.1, 0.5, 0.7, 0.4, 0.5, 0.4, 0.3, 0.4, 0.5, 0.65, 0.75, 0.8, 0.7, 0.25, 0.1, 0.1, 0.75, 0.2, 0.0, 0.0, 0.0, 0.5, 0.65, 0.5]
hours = list(range(25)) # [0, 1, 2, ... 22, 23, 24]
labels = [f'{h:02d}:00' for h in hours] # ["00:00", "01:00", ... "23:00", "24:00"]
f = interp1d(hours, load)
f2 = interp1d(hours, load, kind='cubic')
xnew = np.linspace(0, 24, num=500, endpoint=True)
plt.xticks(np.arange(0, 25, step=1)) # Set label locations.
plt.xticks(np.arange(25), labels) # Set text labels.
plt.xticks(np.arange(25), labels, rotation=90, fontsize=13)
plt.xlim(xmin=0.0)
plt.plot(xnew, f2(xnew), color="gold", linewidth=3)
plt.legend(['Generation'], loc='best')
plt.legend( ['Electricity generation'], bbox_to_anchor=(0.5, 1.2), loc='upper center' , fontsize=16)
plt.ylabel("Electrical power", fontsize=18, labelpad=8)
plt.xlabel("Time of day", fontsize=18, labelpad=8)
plt.xlim(xmin=0.0)
plt.tick_params(labelleft=False)
plt.savefig('Generation_2.png', edgecolor='black', dpi=400, bbox_inches='tight')
plt.show()
Can you tell me how I can do this? I'd appreciate every comment and will be thankful for your help.