gpt4 book ai didi

legend - 使用带有黄砖的子图并丢失图例和标题时的问题

转载 作者:行者123 更新时间:2023-12-01 00:13:29 27 4
gpt4 key购买 nike

将多个黄砖图表放入子图排列时遇到问题。标题和图例仅显示最后一个图表。我尝试了多种编写代码的方法,但无法让所有方法都显示图例和标题。我敢肯定,上类很简单。

这是一段代码:

f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2,figsize=(14, 10))

viz = FeatureImportances(LinearRegression(), ax=ax1)
viz.fit(X_train, y_train)

viz = LearningCurve(LinearRegression(), scoring='r2',cv=10, ax=ax2)
viz.fit(X_train, y_train)

viz = ResidualsPlot(clf, ax=ax3)
viz.fit(X_train, y_train)

viz = PredictionError(LinearRegression(), ax=ax4)
viz.fit(X_train, y_train)
viz.score(X_test, y_test)

viz.poof()

image of plots

最佳答案

@chris-mangum 很抱歉您为此苦苦挣扎。除了show我们还有另一个方法叫做 finalize在这种情况下,finalize 优于 show -- show电话finalize然后显示或 savefig 结束图形,因此在像您这样的多轴图中,您不想调用 poof。

f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2,figsize=(14, 10))

viz = FeatureImportances(LinearRegression(), ax=ax1)
viz.fit(X_train, y_train)
viz.finalize()

viz = LearningCurve(LinearRegression(), scoring='r2',cv=10, ax=ax2)
viz.fit(X_train, y_train)
viz.finalize()

viz = ResidualsPlot(clf, ax=ax3)
viz.fit(X_train, y_train)
viz.finalize()

viz = PredictionError(LinearRegression(), ax=ax4)
viz.fit(X_train, y_train)
viz.score(X_test, y_test)

viz.finalize()

关于legend - 使用带有黄砖的子图并丢失图例和标题时的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55756978/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com