在 Pandas 直方图中设置 y 轴限制
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38424459/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set y axis limit in Pandas histogram
提问by Andy Toulis
I am using Pandas histogram.
我正在使用 Pandas 直方图。
I would like to set the y-axis range of the plot.
我想设置绘图的 y 轴范围。
Here is the context:
这是上下文:
import matplotlib.pyplot as plt
%matplotlib inline
interesting_columns = ['Level', 'Group']
for column in interesting_columns:
data['ranking'].hist(by=data[column], normed=True)
There is a range argument that can filter x-values, but I am unaware of the y equivalent:
有一个范围参数可以过滤 x 值,但我不知道 y 等效项:
hist(by=[column], normed=True, range=[0, 1]) #working argument
hist(by=[column], normed=True, y_range=[0, 1]) #hypothetical argument
I've read a lot of different methods for changing plot ranges using plt attributes. They do not seem to work in a loop and for subplots.
我已经阅读了很多使用 plt 属性更改绘图范围的不同方法。它们似乎不适用于循环和子图。
I am struggling to grasp the right way to approach this problem.
我正在努力掌握解决这个问题的正确方法。
回答by WilliamEllisWebb
If you use
如果你使用
data['ranking'].plot.hist(ylim=(0,1))
it should work.
它应该工作。
回答by Xiao Huang
You can simply add option sharey=True
to make all subplots share the same yaxis limit, similiary using sharex=True
for xaxis
您可以简单地添加选项sharey=True
使所有子图共享相同的 yaxis 限制,类似地sharex=True
用于 xaxis
data['ranking'].hist(by=data[column], sharey=True)
data['ranking'].hist(by=data[column], sharey=True)