0

I have written a simple python code with Spyder to generate a line graph representing Average House price (Y-axis) against the year (x-axis) there are about 600 entries into the data frame for each though as there is data for every month since 1969 to 2019. This has caused the line graphs x-axis to just be a big black bar of overlapping text. The y-axis is fine as it's just adjusted to increments of 20,000. Sorry for the beginner questions I've tried reading some of the resources online but there is often more advanced coding at play that does not work within mine. Thanks in advance :)

import matplotlib.pyplot as plt
import pandas as pd

df = pd.read_csv('ScottishAveragePrices2.csv')

df1 = df.groupby(['Date']).mean().sort_values('AveragePrice')
plt.plot(df['Date'], df['AveragePrice'])

plt.show()enter code here
Sly_Lamp
  • 47
  • 1
  • 6

1 Answers1

0

So you could do two things:
1) Setting the range

matplotlib.pyplot.xticks(range(5))

That would limit the labels on the x-axis.
2) Turning the x-axis label

matplotlib.pyplot.xticks(rotation=45)
SebNik
  • 880
  • 3
  • 10
  • 21
  • 1
    Thank you! I'm not sure how to set a question as answered but this is what the previous poster suggested and it worked a treat. Really appreciate the help bro :) – Sly_Lamp May 03 '20 at 13:57
  • Just tick the hock on he right hand site of my answer. – SebNik May 04 '20 at 08:48