I have a kind of specific question: I was plotting a time series that came from a dataframe with a DatetimeIndex
index, which comes with pandas' specific formatting, like this:
The thing is, the date formatting (obviously) assumes english is my language. In this case, I need the month's legends to be in spanish, that is: change "Dec" for "Dic" and "Jan" for "Ene". I tried saving the ticks' values, modifying them and then replacing them, but I couldn't manage to accomplish the third part of my plan. This is what I tried:
from matplotlib.text import Text
df.plot()
b = (plt.xticks())
b[1][2] = Text(2605, 0, '\n\nDic')
b[1][3] = Text(2610, 0, '\n\nEne\n2020')
ax.set_xticklabels(b)
So b
was originally:
(array([2599, 2601, 2605, 2610], dtype=int64),
[Text(2599, 0, '20'),
Text(2601, 0, '\n\nNov'),
Text(2605, 0, '\n\nDec'),
Text(2610, 0, '\n\nJan\n2020')])
And I changed it to:
(array([2599, 2601, 2605, 2610], dtype=int64),
[Text(2599, 0, '20'),
Text(2601, 0, '\n\nNov'),
Text(2605, 0, '\n\nDic'),
Text(2610, 0, '\n\nEne\n2020')])
But I don't know how to use this. Also, I feel there has to be a simpler way to do this. Do you have any recommendations?
Thanks !