python - 如何绘制直方图并在 python 中并排描述它?

标签 python matplotlib seaborn

下面的代码生成了我的数据集的描述,加上一个直方图,一个在另一个之上...

get_ipython().magic(u'matplotlib inline')
import matplotlib.pyplot as plt
import seaborn as sns

sns.distplot(dfx.hits, bins=20)

dfx.hits.describe()

(而且不是我期望的顺序。)

结果如下:

Description and histogram

但我希望这些数字并排显示。这可能吗?

最佳答案

James 关于使用子图的建议很有帮助,但不如这个问题提供的答案详细:

How to Display Dataframe next to Plot in Jupyter Notebook

Charles Parr 的回答帮助我编写了这段代码:

fig = plt.figure(figsize=(10,4))

ax1 = fig.add_subplot(121)
ax1.hist(dfx.hits, bins=20, color='black')
ax1.set_title('hits x users histogram')

dfxx = dfx.hits.describe().to_frame().round(2)

ax2 = fig.add_subplot(122)
font_size=12
bbox=[0, 0, 1, 1]
ax2.axis('off')
mpl_table = ax2.table(cellText = dfxx.values, rowLabels = dfxx.index, bbox=bbox, colLabels=dfxx.columns)
mpl_table.auto_set_font_size(False)
mpl_table.set_fontsize(font_size)

生成直方图和描述的并排子图:

histogram and description side-by-side with python

关于python - 如何绘制直方图并在 python 中并排描述它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54895350/

相关文章:

python - NoReverseMatch at/rest-auth/password/reset/

python - numpy/scipy/ipython :Failed to interpret file as a pickle

python - 使用 matplotlib 绘制百分位数

python - 如何使用seaborn热图制作jupyter HTML-matplotlib动画?

python - Django self.request 不通过查询进行过滤

字符串中的Python类

python - 如何将 help.chm 文件合并到 python 应用程序中?

python - Seaborn Countplot并未显示所有类别

python - 使用 kdeplot 与 searborn 进行绘图时,将图例移动到框外时出现错误 : No handles with labels found to put in legend.

python - 如何根据列数据类型创建不同绘图组