【发布时间】:2022-08-14 11:25:48
【问题描述】:
如何编辑情节图例,以便将“颜色”和“符号”合并为一个?
import pandas as pd
import plotly.express as px
import numpy as np
from sklearn.decomposition import PCA
pca = PCA()
X_pca = pca.fit_transform(X)
fig = px.scatter(X_pca, x=0, y=1, color=df[\"subtype\"], width=600, height=600, color_discrete_sequence=[\"red\", \"orange\", \"brown\", \"green\"], title=\"Kernel PCA - tumor subtype vs normal\", symbol=df[\"subtype\"], symbol_sequence=[\'circle\', \'circle\', \'circle\', \'square\'])
fig.update_traces(marker=dict(size=5, line=dict(width=0.5, color=\'DarkSlateGrey\')), selector=dict(mode=\'markers\'))
fig.update_xaxes(automargin=True)
fig.update_yaxes(automargin=True)
fig.update_layout({\'plot_bgcolor\': \'rgb(240,240,240)\', \'paper_bgcolor\': \'rgb(240,240,240)\',})
fig.show()
fig.write_image(\"meth_subtype_pca.png\")
电流输出:
图例有\"color, symbol\"...\"kirp, kirp\" 等。我想用\"subtype\"...\"KIRP\" 替换它。