Home > Back-end >  X axis for plt plot python is cluttered together
X axis for plt plot python is cluttered together

Time:04-01

plt.figure(figsize=(4,4))
aapl_data.plot.line(x='Date',y='Adj Close',title='test')
plt.ylabel('Adj Close')plt.show()

enter image description here

How do i declutter the X axis. I tried using figsize in the code but it does not do anything

CodePudding user response:

Better show the whole code. Since I'm not sure if you have such a string: ax = plt.axes()

ax.xaxis.set_major_locator(mdates.DayLocator(interval = 3))

CodePudding user response:

Try to formate the date

ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%b'))

CodePudding user response:

There can be two solutions to this problem.

  1. Increasing the width of the window. This can be achieved by:
import matplotlib.pyplot as plt


fig = plt.figure(figsize=(40,4))
fig.add_subplot(1,1,1).plot([1,2,3], [1,2,3])
plt.show()

  1. Making the labels vertical rather than horizontal. This can be done by:
plt.xticks(range(10), rotation='vertical')
  • Related