1

I'm trying to plot some data for school project. However an ugly shadow appears when I do so. I have no clue of what it can be.

Here is my code:

index_labels = np.empty(len(smoothed), dtype=object)
for i in range(len(index_labels)):
    index_labels[i] = ""
    if i%365 == 0:
        index_labels[i] = 2015 + int(i//365)

plt.scatter(smoothed.index, smoothed.national, label='PV load factor rolling mean over 24h.')
plt.plot(smoothed.index, sin_ref, color='red', label='Sinusoidal reference')
ax = plt.gca()
ax.set_xticklabels(index_labels)
# plt.legend()
plt.show()

and here is the different variables used so you have an idea:

enter image description here

and a zoom on the plot :

enter image description here

Thanks to all of you! Greetings :)

TheBlackDev_
  • 93
  • 10

1 Answers1

2

Solution from @BigBen:

from matplotlib.ticker import MultipleLocator

plt.scatter(smoothed.index, smoothed.national, label='PV load factor rolling mean over 24h.')
plt.plot(smoothed.index, sin_ref, color='red', label='Sinusoidal reference')
ax = plt.gca()
ax.xaxis.set_major_locator(MultipleLocator(730))
plt.show()

Multiple has a very good name: it only shows the label for the multiple of n.

enter image description here

EDIT: as find later, matplotlib do auto axis labeling for dates. Only problem was that column was recognized as string. pandas.to_datetime allow you to convert it back to pandas datetime type.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
TheBlackDev_
  • 93
  • 10