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
  • 49,299
  • 29
  • 200
  • 290

2 Answers2

7

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

plt.subplots_adjust(hspace=0.5) 

enter image description here

Wayne Werner
  • 49,299
  • 29
  • 200
  • 290
Joe
  • 12,057
  • 5
  • 39
  • 55
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
  • 10,754
  • 11
  • 52
  • 111