How to change legends or names on x axis of boxplot pandas

1

I have created a dataframe with columns of temperatures per month.

When I do boxplot with pandas, the name I put on the columns appears on the x-axis, but I want to change them in the figure.

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

df = pd.DataFrame(data = matriz, columns=['T Enero','T Febrero','T Marzo','T Abril','T Mayo','T Junio','T Julio','T Agosto','T Septiembre','T Octubre','T Noviembre','T Diciembre'])

#Boxplot Temperaturas de Tropopausa     
plt.figure(figsize=(14,11))
plt.xlabel('Box plot por Mes',fontsize=15) 
plt.ylabel('Temperatura (K)',fontsize=15)
plt.title(('Temperaturas de Tropopausa en Córdoba').decode('utf8'))   #decode para que no den error los tildes
boxplot=df.boxplot(column=['T Enero','T Febrero','T Marzo','T Abril','T Mayo','T Junio','T Julio','T Agosto','T Septiembre','T Octubre','T Noviembre','T Diciembre'],rot=45,fontsize='medium')
plt.savefig(rutasalfig+'tempTrop.png',dpi=200)

Box plot

  

I want to change the x-axis labels and put what I want.

Try with:

labels = ("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L")
boxplot=df.boxplot(column=['T Enero','T Febrero','T Marzo','T Abril','T Mayo','T Junio','T Julio','T Agosto','T Septiembre','T Octubre','T Noviembre','T Diciembre'],rot=45,fontsize='medium',**labels=labels**)

and it did not work.

    
asked by Ines 23.08.2018 в 16:07
source

1 answer

0

Finally I found the solution

I added the line

plt.xticks ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], fontsize = 15)

And it worked

The code stayed like this:

plt.figure (figsize = (14,11))

boxplot = df.boxplot (column = ['T January', 'T February', 'T March', 'T April', 'T May', 'T June', 'T July', 'T August ',' T September ',' T October ',' T November ',' T December '], rot = 45)

plt.xlabel ('Box plot per Month', fontsize = 15)

plt.ylabel ('Temperature (K)', fontsize = 15)

plt.title (('Tropopause Temperatures in Córdoba'). decode ('utf8'), fontsize = 20) #decode so that the tildes do not give an error

plt.xticks ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], fontsize = 15)

plt.savefig (routesalfig + place + 'tempTrop.png', dpi = 200)

    
answered by 29.08.2018 / 16:21
source