Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何绘制直方图并在python中并排描述它?_Python_Matplotlib_Seaborn - Fatal编程技术网

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

如何绘制直方图并在python中并排描述它?,python,matplotlib,seaborn,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() (而且不是按照我预期的顺序。) 结果如下: 但我想要这些数字并排出现。这可能吗?您需要使用matplotlib的内置子绘图来绘制(

下面的代码生成我的数据集的描述,加上一个柱状图,一个在另一个之上

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

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

dfx.hits.describe()
(而且不是按照我预期的顺序。)

结果如下:


但我想要这些数字并排出现。这可能吗?

您需要使用matplotlib的内置子绘图来绘制(2,1)绘图,并将第一个绘图放置在(0,0),第二个绘图放置在(1,0)。 你可以找到不太好的官方文档

我建议查看python-course.eu上的指南:

另一个原因是它的顺序不正确,因为您没有调用plt.show()或seaborn等效函数,因此ipython在调用图时最后一次吐出它,而没有分配给其他地方

类似于如果您有:

import matplotlib.pyplot as plt

plt.plot(range(10),range(10))
print("hello")
输出为:

>>hello
>>'Some Graph here'

James关于使用子图的建议很有帮助,但没有这个问题的答案那么详细:

查尔斯·帕尔的回答帮助我编写了以下代码:

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)
它生成了直方图和描述的并排子图: