I make a line graph more smooth by applying the following lines of code (based on
Based on this figure, I have 2 questions:
- How can I limit the number of ticks on the x-axis, so that only the years 2000, 2005, 2010, 2015, and 2020 are visualized? - what makes it potentially more difficult is that two arguments are given for
plt.xticks()
- How can I limit the number of marker points so that it matches the number of years and its related positions (so having 23 marker points eventually)?
CodePudding user response:
This should do the trick. First you remove the marker for the spline plot, next you add a scatter plot to show the desired markers.
plt.plot(xnew, smooth, color = 'black', marker = '')
plt.scatter(idx, random_values, color = 'black', marker = '.')
xtickYears = list(range(2000, 2021, 5))
plt.xticks([years.index(i) for i in xtickYears], xtickYears)