Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 同一行的不同标记颜色_Python_Plotly_Plotly Dash - Fatal编程技术网

Python 同一行的不同标记颜色

Python 同一行的不同标记颜色,python,plotly,plotly-dash,Python,Plotly,Plotly Dash,我正在尝试使用plotly和dash为webapp创建一个简单的折线图。我想画一条连接两点的线。我想要一个是红色的,另一个是绿色的。以下是我目前掌握的情况: import dash import dash_core_components as dcc import dash_html_components as html import plotly.graph_objs as go external_stylesheets = ['https://codepen.io/chriddyp/pen/

我正在尝试使用plotly和dash为webapp创建一个简单的折线图。我想画一条连接两点的线。我想要一个是红色的,另一个是绿色的。以下是我目前掌握的情况:

import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets = external_stylesheets)
graph = dcc.Graph(figure = {
    'data' : [
        go.Scatter(x = [1,4], y = [2,3], mode = 'lines+markers', opacity = 0.7, marker = {
            'size' : 15,
            'line' : {'width' : 0.5, 'color' : 'black'}
        })
    ]
})
app.layout = html.Div([graph])
if __name__ == '__main__':
    app.run_server(debug = False)
我正在Jupyter笔记本上运行这段代码,里面有所有最新的软件包。 如果我运行这段代码,我会得到我想要的线图,但两个点都是蓝色的。我希望(1,2)对应的点是红色,(4,3)对应的点是绿色。我该怎么做呢?
提前非常感谢

我认为这个问题的公认解决方案是在图形数据中有3个不同的
go.scatter()
对象。一个用于线条,一个用于每个标记。你的应用程序最终会变成这样:

import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets = external_stylesheets)
graph = dcc.Graph(figure = {
    'data' : [
        go.Scatter(x = [1,4], y = [2,3], mode = 'lines+markers', opacity = 0.7, 
                   marker={'color':["red","green"], "size":15})
    ]
})
app.layout = html.Div([graph])

if __name__ == '__main__':
    app.run_server(debug = False)

你好非常感谢您的回复。这似乎确实解决了我的问题。我想知道…还有别的办法吗?绘制3倍数量的图形似乎效率低下。哦,有更好的方法。对不起,我想你必须为不同的颜色条做不同的标记。见我编辑的答案