[英]Dual Y-axis horizontal line position access in stratx plot
I want to draw a horizontal line going through the 0.0 point over the plot produced by stratx's ( https://github.com/parrt/stratx ) plot_stratpd method.我想在stratx( https://github.com/parrt/stratx ) plot_stratpd 方法产生的 plot 上画一条穿过 0.0 点的水平线。
How can I access the left Y-axis in this case, so that I can use y=0.0
?在这种情况下如何访问左 Y 轴,以便可以使用
y=0.0
?
from stratx.partdep import *
X = df.drop('user_retained', axis=1)
y = df['user_retained']
plt.figure(figsize=(16,16), dpi= 80, facecolor='w', edgecolor='k')
plot_stratpd(X, y, 'percentage_of_points', 'user_retained', yrange=(-0.3, 0.6), n_trials=10)
plt.tight_layout()
plt.axhline(y=134, alpha=1, linewidth = 2, linestyle = '-')
plt.show()
Set up an Axes
and pass it to plot_stratpd
.设置一个
Axes
并将其传递给plot_stratpd
。 You can then use this Axes to plot the horizontal line at regular data coordinates:然后,您可以使用此 Axes 到 plot 常规数据坐标处的水平线:
fig,ax = plt.subplots(figsize=(16,16), dpi= 80, facecolor='w', edgecolor='k')
plot_stratpd(X, y, 'percentage_of_points', 'user_retained', yrange=(-0.3, 0.6), n_trials=10, ax=ax)
ax.axhline(y=0, alpha=1, linewidth = 2, linestyle = '-')
Example:例子:
from sklearn.datasets import load_diabetes
from stratx.partdep import *
import matplotlib.pyplot as plt
diabetes = load_diabetes()
df = pd.DataFrame(diabetes.data, columns=diabetes.feature_names)
df['y'] = diabetes.target
X = df.drop('y', axis=1)
y = df['y']
fig,ax = plt.subplots()
plot_stratpd(X, y, 'bmi', 'y', n_trials=10, ax=ax)
ax.axhline(0)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.