如何在形状摘要图上更改轴

发布于 2025-02-04 10:09:22 字数 467 浏览 4 评论 0原文

我正在遵循列出的代码,仅具有略有不同的值(因此我的代码完全如链接中所述)。

我的输出看起来像这样:

”在此处输入图像说明”

有人可以向我展示如何更改X轴(理想情况下是自动的,因为我必须为不同的数据集制作多个图),因此数据不那么堆积向上看到完整的情节?

I am following the code listed here, just with slightly different values (so my code is exactly as described in the link).

My output looks like this:

enter image description here

Would someone be able to show me how to change the X axis (ideally automatically, as I have to make multiple plots for different data sets), so the data is less bunched up and the full plot is seen?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青衫负雪 2025-02-11 10:09:22

关于问题中链接的代码,您可以在计算shap_values之后尝试以下解决方案:

import matplotlib.pyplot as plt 
.
.
# Calculate shap_values
fig = shap.summary_plot(shap_values[1], X_test, show=False)
_, h = plt.gcf().get_size_inches()
plt.gcf().set_size_inches(h*5, h)
plt.show()

import matplotlib.pyplot as plt 
.
.
# Calculate shap_values
shap.summary_plot(shap_values[1], X_test, show=False)
ax = plt.gca()

# You can change the min and max value of xaxis by changing the arguments of:
ax.set_xlim(-0.5, 0.5) 
plt.show()

您也可以将上述解决方案组合起来以获取该解决方案最佳解决方案。

请参阅此答案以获取更多信息。

With reference to the code linked in the question, you can try the following solution(s) just after shap_values are calculated:

import matplotlib.pyplot as plt 
.
.
# Calculate shap_values
fig = shap.summary_plot(shap_values[1], X_test, show=False)
_, h = plt.gcf().get_size_inches()
plt.gcf().set_size_inches(h*5, h)
plt.show()

OR

import matplotlib.pyplot as plt 
.
.
# Calculate shap_values
shap.summary_plot(shap_values[1], X_test, show=False)
ax = plt.gca()

# You can change the min and max value of xaxis by changing the arguments of:
ax.set_xlim(-0.5, 0.5) 
plt.show()

You can also combine the above solutions to get the best resolution for your result.

Please refer to this answer for more information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文