-1

I created a boxplot out of a pandas df by running the following:

ax = df1.boxplot(column=['data1'], by=['category'], grid=False, figsize=(6,5))

and the resulting boxplot came with:

  • a default title (ie. grouped title): "Boxplot grouped by category" --> see yellow
  • a subtitle (what would be the "usual" title for other graph types): "data1" --> see green

enter image description here

When I tried to change the grouped title by passing the title argument into the boxplot function, this didn't work (although it's worked for other chart types like barh)

   ax = df1.boxplot(column=['data1'], by=['category'], grid=False, figsize=(6,5), title = 'my_title')

If we use the ax.set_title() approach as described here, it will change the boxplot subtitle but NOT the grouped title.

Please note that my question does not duplicate this one, as that post's solution will only affect the subtitle instead of the grouped title, and I'm looking for a change in the boxplot's grouped title

Scinana
  • 402
  • 3
  • 14
  • 1
    Use `suptitle`: https://stackoverflow.com/questions/23507229/set-no-title-for-pandas-boxplot-groupby – Ollie Mar 02 '21 at 20:05

2 Answers2

1

You can use plt.title or ax.set_title functions to set title.

koPytok
  • 3,453
  • 1
  • 14
  • 29
1

Use suptitle

ax.get_figure().suptitle('My Title')
Vishnudev Krishnadas
  • 10,679
  • 2
  • 23
  • 55