0

I want to plot this data:

datetime
2021-12-06 00:00:00     40354
2021-12-06 00:05:00     94557
2021-12-06 00:10:00     53314
2021-12-06 00:15:00     91334
2021-12-06 00:20:00     94168
2021-12-06 00:25:00     92049
2021-12-06 00:30:00     89400
2021-12-06 00:35:00     86499
2021-12-06 00:40:00     87517

I use

plt.plot(data)
plt.xticks(rotation=90)
plt.axis('tight')
plt.savefig('plot.png')
plt.close()

But the x label is cutted off :

enter image description here

I went through this question X-axis Label Gets Cut Off Of Graph - Python Matplotlib and I tried to use plt.tight_layout() and plt.savefig('plot.png', bbox_inches='tight') but it did not help. Can you help me please?

vojtam
  • 1,157
  • 9
  • 34

1 Answers1

0

You can try this

import numpy as np
from datetime import datetime
from matplotlib import pyplot as plt 

date_t = [str(datetime(2021,12,6,0,item,0,0)) for item in range(0,50,5)]
y_vals = np.random.randint(100,200,len(date_t))

fig,ax = plt.subplots(figsize=(8,6))
ax.plot(y_vals)
ax.set_xticks(range(len(y_vals)))
ax.set_xticklabels(date_t)
ax.tick_params(axis='x',labelrotation=90)

The output is like

test

meTchaikovsky
  • 7,478
  • 2
  • 15
  • 34