[英]matplotlib vlines dynamic ymax parameter from seaborn distplot
I'm plotting a seaborn
distplot
from pandas dataframe as my initial working matplotlib canvas.我正在从
seaborn
数据distplot
绘制一个seaborn
distplot
作为我最初的工作 matplotlib 画布。 Then to add more info to the canvas I'm using vlines
as vertical markers.然后向画布添加更多信息,我使用
vlines
作为垂直标记。 However I didn't find a trivial way to define dynamic ymax
param for vlines, since it is distribution dependent.但是,我没有找到一种为 vlines 定义动态
ymax
参数的简单方法,因为它依赖于分布。
sns.distplot(data.values) # distribution chart
plt.vlines(x=[1,2], ymin=0, ymax=?)
Is there a way to pass the ymax
acccording to the highest value in the chart?有没有办法根据图表中的最大值传递
ymax
? (so the plot height and the vertical lines height will be aligned). (因此绘图高度和垂直线高度将对齐)。 I considered something like:
我考虑过类似的事情:
plt.vlines(x=[1,2], ymin=0, ymax=data.values.max())
However the maximal value of data.values
is actually represented on the X axis.然而
data.values
的最大值实际上表示在 X 轴上。
You may loop over the input points (useful if there aren't too many, say <=10)您可以循环输入点(如果没有太多,则很有用,例如 <=10)
for i in [1,2]:
ax.axvline(i)
Or you can supply a blended transform for the vlines
,或者您可以为
vlines
提供混合变换,
ax.vlines(x=[1,2], ymin=0, ymax=1, transform=ax.get_yaxis_transform())
I found a way to retrieve the coordinates of the canvas:我找到了一种检索画布坐标的方法:
dist = sns.distplot(data.values)
ymin,ymax = dist.get_ylim()
Then it's quite straightforward:然后就很简单了:
plt.vlines(x=[1,2], ymin=ymin, ymax=ymax)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.