6

I'm trying to plot some histogram using pandas. Here's some sample code that does something similar to what I'm doing:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
ts = pd.Series(np.random.randn(1000), index=pd.date_range('2018-10-14', periods=1000))
df = pd.DataFrame(np.random.randn(1000, 6), index=ts.index, columns=['A', 'B', 'C', 'D', 'E', 'F'])
df = df.cumsum()
df.hist()

The data shows in a histogram fine, with one slight problem:

six histograms with a D overlapping -20

My histogram labels at the top overlap the X-axis labels at the bottom of the next row.

I would love to be able to add some spacing between these, but I haven't found any information about how to do this.

How can I increase the padding between my plots using pandas and matplotlib?

Wayne Werner
  • 45,646
  • 26
  • 189
  • 275

2 Answers2

6

You can use subplots_adjust after your df.hist() call:

plt.subplots_adjust(hspace=0.5) 

enter image description here

Wayne Werner
  • 45,646
  • 26
  • 189
  • 275
Joe
  • 11,147
  • 5
  • 36
  • 50
1

As joe Specified you can specify hspace in your code, Moreover you can click on configure subplots button in after plt.show(). Modify hspace value in this scale dynamically.

Step-1

enter image description here

Step-2

enter image description here

Step-3

enter image description here

Mohamed Thasin ah
  • 9,418
  • 9
  • 43
  • 83