I want to make the x axis of a figure wider in matplotlib and I use the following code. But it seems that figsize does not have any effect. How I can change the size of the figure?
data_dates = np.loadtxt(file,usecols = 0, dtype=np.str)
data1 = np.loadtxt(file,usecols = 1)
data2 = np.loadtxt(file,usecols = 2)
data3 = np.loadtxt(file,usecols = 3)
plt.plot(figsize=(30,5))
plt.plot(data_dates,data1, label = "T")
plt.plot(data_dates,data2, label = "WS")
plt.plot(data_dates,data3, label = "WD")
plt.xlabel('Date', fontsize=8)
plt.xticks(rotation=90,fontsize=4)
plt.ylabel(' Percentage Difference (%)')
plt.legend()
plt.savefig(outfile,format='png',dpi=200,bbox_inches='tight')
a sample of the file is
01/06/2019 0.1897540512577196 0.28956205456965856 0.10983099750547703
02/06/2019 0.1914523564094276 0.1815325705314345 0.0004533827128655877
03/06/2019 0.2365346386184113 0.12301344973593868 0.058843355966174876
04/06/2019 0.2085897993039386 0.005466902564359565 0.014087537281676313
05/06/2019 0.15563355684612554 0.16249844426472368 0.11036007669758358
06/06/2019 0.11981475728282368 0.11015459703126898 0.03501167308950372
fig, ax = plt.subplots(1, 1)
fig.set_size_inches(30, 5)
plt.plot(data_dates,data1, label = "T")
plt.plot(data_dates,data2, label = "WS")
plt.plot(data_dates,data3, label = "WD")
plt.xlabel('Date', fontsize=8)
plt.xticks(rotation=90,fontsize=4)
plt.ylabel(' Percentage Difference (%)')
plt.legend()
plt.savefig("test.png",format='png',dpi=200,bbox_inches='tight')
Instead of creating the figure explicitly using subplots you could also use the get-current-figure method: fig = plt.gcf()
.