When grasping trends in samples and time series data, it is convenient to plot a scatter plot (+ solid line) on the left side and a histogram on the right side as shown below. In such a case, use gridspec
to adjust the width of the graph with matplotlib
. If you want to add a histogram on the upper side as well, it is convenient to use seaborn jointtplot.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
%matplotlib inline
plt.rcParams['font.size'] = 15
x = np.random.randn(1000)
gs = gridspec.GridSpec(1, 2, width_ratios=[4,1], height_ratios=[1] ,wspace=0.05)
plt.figure(figsize=(8,3))
plt.subplot(gs[0])
plt.scatter(range(len(x)),x,color='k',s=2)
plt.ylim(-4,4)
plt.xlabel('index')
plt.ylabel('x')
plt.axhline(y=0,color='gray',lw=1)
plt.subplot(gs[1])
plt.hist(x,orientation='horizontal',bins=20,color='k')
plt.tick_params(left=False,labelleft=False)
plt.ylim(-4,4)
plt.xlabel('freq.')
plt.axhline(y=0,color='gray',lw=1)
plt.show()
Recommended Posts