Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I increase the padding on my pandas dataframe plot? [duplicate]

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?

like image 382
Wayne Werner Avatar asked Nov 15 '18 06:11

Wayne Werner


2 Answers

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

plt.subplots_adjust(hspace=0.5) 

enter image description here

like image 182
Joe Avatar answered Oct 08 '22 01:10

Joe


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

like image 30
Mohamed Thasin ah Avatar answered Oct 08 '22 00:10

Mohamed Thasin ah