[英]How to change markers shape manually in plotly interactive plot
我試圖在可交互的繪圖中為不同的顏色分配不同的標記。 通過使用以下腳本,我可以獲得交互式繪圖,可以更改標記“o”的大小,可以注釋文本。 附上我得到的情節。 我想更改附加的 PCA 圖中的標記。
#腳本
import plotly
import plotly.plotly as py
from plotly.graph_objs import Scatter
import plotly.graph_objs as go
plotly.tools.set_credentials_file(username='XXX', api_key='XXXX')
#py.plot(data, filename = 'basic-line', auto_open=True, Transforms = 'Split')
trace1 = Scatter(
x=x1, # x-coordinates of trace
y=y1, # y-coordinates of trace
mode='markers + text', # scatter mode
text = label1, textposition='top center',
marker = dict(size = 15, color = color_3),
textfont=dict(
color='black',
size=18,
family='Times New Roman'
)
)
layout = {
'xaxis': {
'showticklabels': False,
'showgrid': False,
'zeroline': False,
},
'yaxis': {
'showticklabels': False,
'showgrid': False,
'zeroline': False,
}
}
data = [trace1]
fig = {
'data': data,
'layout': layout,
}
py.plot(fig, filename='example1')
我手動更改了散點的顏色,我有一個顏色列表(color_3)。 我可以為每種顏色分配一個標記,比如marker_list。 但是我怎樣才能在 plotly 中使用這個 marker_list 來獲得類似於附加的 PCA 圖的圖? 在做 PCA 繪圖時,我將它添加到 ax.scatter 中,請參閱下面的片段:
for i in range(len(marker_list)):
ax.scatter(x1[i], y1[i], color = color_3[i], s=150, marker=marker_list[i], alpha=0.8, edgecolors='none')
我可以在上述腳本的某處使用相同的標記列表來獲得交互式繪圖嗎? 任何幫助,將不勝感激。 提前致謝。
您可以使用symbol
屬性設置標記的形狀,例如:
trace1 = Scatter(
x=x1, # x-coordinates of trace
y=y1, # y-coordinates of trace
mode='markers + text', # scatter mode (more in UG section 1)
text = label1, textposition='top center',
marker = dict(size = 15, color = color_3, symbol = 'cross'), # Add symbol here!
textfont=dict(
color='black',
size=18,
family='Times New Roman'
)
可以在文檔中找到不同形狀的概述
當然,您也可以按類傳遞不同形狀的列表,就像您對顏色所做的那樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.