Home > database >  Change y-axis range in Pandas.boxplot()
Change y-axis range in Pandas.boxplot()

Time:02-06

I use the following boxplot function from Pandas,

df.boxplot(column=['D1', 'D2'])

and I would like to change the y-axis range. However, I didn't see such an option in the document. Any idea for that?

CodePudding user response:

You can do so editing the axis-object - you can either do

ax = df.boxplot(column=['D1', 'D2'])
ax.set_ylim(0, 10)

or

import matplotlib.pyplot as plt
fix, ax = plt.subplots(1, 1)
df.boxplot(column=['D1', 'D2'], ax=ax)
ax.set_ylim(0, 10)

figure is the whole graphic, ax is the diagram. plt.subplots(1, 1) is the number of diagrams(rows, columns), in this case 1 - so ax is just one diagram. Otherwise ax would be a list of axis objects.

  •  Tags:  
  • Related