i have a multilevel index series whose outer level index is month and inner level index is day let say it is stored in series
print(series)
Please see the output->output
So to make plot i use the below code
series.plot.line(figsize=(20,10))
i am getting
please see the output->
output
but i want xticks to be [January, February,……,December] instead of those tuple values how can i do that???
>Solution :
If need only months names is possible remove days from Multiindex by Series.droplevel and convert to datetimes with DatetimeIndex.month_name:
series.index = pd.to_datetime(series.index.droplevel(1), format='%m').month_name()
series.plot.line(figsize=(20,10))
Or if need more complex format, e.g. days with month names use matplotlib.dates.DateFormatter with convert MulitIndex to datetimes:
from matplotlib.dates import DateFormatter
series.index = pd.to_datetime([f'2023-{m}-{d}' for m, d in series.index])
ax = series.plot.line(figsize=(20,10))
date_form = DateFormatter("%d-%B")
ax.xaxis.set_major_formatter(date_form)