I have to edit the xticks of a histogram that I have painted with .plot, the xticks represent the months in datetime. I would like to display the months, I have tried using a list.
listaMeses = ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre']
histograma2021 = df_logsFinalizados2021.plot(kind='bar', title = 'Histograma 2021 de viajes por mes')
histograma2021.set(xlabel='Número de viajes', ylabel = 'Mes donde finalizó el viaje', xticks = listaMeses)
I get the following error:
ConversionError: Failed to convert value(s) to axis units: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre']
Attached image of the histogram.
I don't know if it's a misconception or if I'm close to the goal.
Thanks in advance!
You have to change the last line of your code, removing the reference to
xticks
, and add a line specifying what you want to put, and where.According to the official matplotlib documentation, the correct way to use xticks is:
xticks([lista-posiciones], [lista-etiquetas])
. The code would look like this:Note that your histogram only has 11 months in the data, so you have to match the list of months to the xticks... you have December left over.
Edit: matplotlib was not used. I mistakenly thought another python module was being used. If you are using pandas , the correct answer would be to add this line of code: