[英]Python Change axis on Multi Histogram plot
I have a pandas dataframe df
for which I plot a multi-histogram as follow :我有一个 Pandas 数据框df
,我为它绘制了一个多直方图,如下所示:
df.hist(bins=20)
This give me a result that look like this (Yes this exemple is ugly since there is only one data per histogram, sorry) :这给了我一个看起来像这样的结果(是的,这个例子很难看,因为每个直方图只有一个数据,抱歉):
I have a subplot for each numerical column of my dataframe.我的数据框的每个数字列都有一个子图。
Now I want all my histograms to have an X-axis between 0 and 1. I saw that the hist() function take a ax
parameter, but I cannot manage to make it work.现在我希望我的所有直方图都有一个介于 0 和 1 之间的 X 轴。我看到 hist() 函数采用ax
参数,但我无法使其工作。 How is it possible to do that ?怎么可能呢?
EDIT :编辑 :
Here is a minmal example :这是一个最小的例子:
import pandas as pd
import matplotlib.pyplot as plt
myArray = [(0,0,0,0,0.5,0,0,0,1),(0,0,0,0,0.5,0,0,0,1)]
myColumns = ['col1','col2','col3','co4','col5','col6','col7','col8','col9']
df = pd.DataFrame(myArray,columns=myColumns)
print(df)
df.hist(bins=20)
plt.show()
Here is a solution that works, but for sure is not ideal:这是一个有效的解决方案,但肯定不是理想的:
import pandas as pd
import matplotlib.pyplot as plt
myArray = [(0,0,0,0,0.5,0,0,0,1),(0,0,0,0,0.5,0,0,0,1)]
myColumns = ['col1','col2','col3','co4','col5','col6','col7','col8','col9']
df = pd.DataFrame(myArray,columns=myColumns)
print(df)
ax = df.hist(bins=20)
for x in ax:
for y in x:
y.set_xlim(0,1)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.