亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Plotly:如何僅使用一條跡線來定義一個開放標記而不需要一條線穿過它?

Plotly:如何僅使用一條跡線來定義一個開放標記而不需要一條線穿過它?

眼眸繁星 2023-08-08 16:30:35
我想用圓開放標記繪制“線條+標記”圖,而不讓線條穿過它。import plotly.graph_objects as goimport numpy as npx = np.arange(10)fig = go.Figure()fig.add_trace(    go.Scatter(        x=x, y=x**2,        mode='lines+markers',        line=dict(color='green'),        marker_size=16,        marker_symbol='circle-open'    ))fig.update_layout(    plot_bgcolor='white')fig.show()這會產生一條穿過開放標記的線。然后我嘗試在線條頂部添加背景色標記 - 但隨后在圖例中我只得到標記或線條,而不是兩者組合。有沒有辦法以這種方式獲得帶有標記和線條的圖例?fig = go.Figure()fig.add_trace(    go.Scatter(        x=x, y=x**2,        mode='lines',        line=dict(color='red'),        showlegend=False,        legendgroup='legend'    ))fig.add_trace(    go.Scatter(        x=x, y=x**2,        mode='markers',        marker_color='white',        # line=dict(color='green'),        marker_size=12,        marker_symbol='circle',        marker_line=dict(            width=3,            color='red'        ),    legendgroup='legend'    ))fig.update_layout(    plot_bgcolor='white',)fig.show()
查看完整描述

1 回答

?
郎朗坤

TA貢獻1921條經驗 獲得超9個贊

使用幾個屬性的正確組合應該可以幫助您實現這一目標:

  1. marker_symbol='circle'

  2. marker_color = 'white'

  3. marker = dict(line = dict(color='green', width = 2))

陰謀

https://img1.sycdn.imooc.com//64d1fd5000013e0112200405.jpg

完整代碼:

import plotly.graph_objects as go

import numpy as np

x = np.arange(10)


fig = go.Figure()

fig.add_trace(

    go.Scatter(

        x=x, y=x**2,

        mode='lines+markers',

        line=dict(color='green'),

        marker_size=16,

        marker_symbol='circle',

        name = 'no line through this',

        showlegend = True,

        

        marker_color = 'white',

        marker = dict(line = dict(color='green', width = 2))

    )

)

fig.update_layout(

    plot_bgcolor='white'

)

fig.show()


查看完整回答
反對 回復 2023-08-08
  • 1 回答
  • 0 關注
  • 124 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號