如何从Python中的情节子图中删除多个传说
我正在研究虹膜数据集。要拥有与我相同的数据使用此代码 -
from sklearn.datasets import load_iris
data = load_iris()
features_df = pd.DataFrame(data.data, columns = data.feature_names)
target = pd.DataFrame(data.target, columns = ["species"])
target.replace(dict(zip(np.unique(data.target), data.target_names)), inplace = True)
df = pd.concat([features_df, target], axis = 1)
使用此代码,我能够生成4个散点图作为子图 -
fig = make_subplots(rows = 2, cols = 2)
plots_xy = [("sepal length (cm)", "petal length (cm)"), ("sepal width (cm)", "petal width (cm)"), ("sepal length (cm)", "sepal width (cm)"), ("petal length (cm)", "petal width (cm)")]
plot_coords = list(itertools.product([1,2], repeat = 2))
for index, plot in enumerate(plots_xy):
fig.add_traces(px.scatter(data_frame = df, x = plot[0], y = plot[1], color = "species").data, rows = plot_coords[index][0], cols = plot_coords[index][1])
fig.update_xaxes(title_text = plot[0])
fig.update_yaxes(title_text = plot[1])
fig.update_layout(width = 1200, height = 900)
fig.show()
绘图 -
如您所见,传说在这里重复。我该如何停止这个,只有一个传奇人物?
I am working on the Iris Dataset. To have the same data as me use this code -
from sklearn.datasets import load_iris
data = load_iris()
features_df = pd.DataFrame(data.data, columns = data.feature_names)
target = pd.DataFrame(data.target, columns = ["species"])
target.replace(dict(zip(np.unique(data.target), data.target_names)), inplace = True)
df = pd.concat([features_df, target], axis = 1)
Using this code I am able to generate 4 scatterplots as subplots -
fig = make_subplots(rows = 2, cols = 2)
plots_xy = [("sepal length (cm)", "petal length (cm)"), ("sepal width (cm)", "petal width (cm)"), ("sepal length (cm)", "sepal width (cm)"), ("petal length (cm)", "petal width (cm)")]
plot_coords = list(itertools.product([1,2], repeat = 2))
for index, plot in enumerate(plots_xy):
fig.add_traces(px.scatter(data_frame = df, x = plot[0], y = plot[1], color = "species").data, rows = plot_coords[index][0], cols = plot_coords[index][1])
fig.update_xaxes(title_text = plot[0])
fig.update_yaxes(title_text = plot[1])
fig.update_layout(width = 1200, height = 900)
fig.show()
The plot -
As you can see, the legends are getting repeated here. How can I stop this and only have one legend for the whole plot?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)