0
month = ['January', 'February', 'March', 'April', 'May', 'June', 'July',
         'August', 'September', 'October', 'November', 'December']
high_2000 = [32.5, 37.6, 49.9, 53.0, 69.1, 75.4, 76.5, 76.6, 70.7, 60.6, 45.1, 29.3]
low_2000 = [13.8, 22.3, 32.5, 37.2, 49.9, 56.1, 57.7, 58.3, 51.2, 42.8, 31.6, 15.9]
high_2007 = [36.5, 26.6, 43.6, 52.3, 71.5, 81.4, 80.5, 82.2, 76.0, 67.3, 46.1, 35.0]
low_2007 = [23.6, 14.0, 27.0, 36.8, 47.6, 57.7, 58.9, 61.2, 53.3, 48.5, 31.0, 23.6]

d = pd.DataFrame([month, high_2000, low_2000, high_2007, low_2007]).T
d.columns = ['month', 'high_2000', 'low_2000', 'high_2007', 'low_2007']

fig1 = px.line(d, 
               x='month',
               y=list(d.columns)[1:],
               color_discrete_map={
                   'high_2000': 'aquamarine', 'low_2000': 'aquamarine',
                   'high_2007': 'crimson', 'low_2007': 'crimson'
                },
                line_dash_map={
                   'high_2000': 'solid', 'low_2000': 'dot',
                   'high_2007': 'solid', 'low_2007': 'dot'
                })
# st.plotly_chart(fig1, use_container_width=True)
fig1.show()

使用上面的代码,图如下 在此处输入图像描述

没有引发错误,但line_dash_map参数不起作用。顺便说一句,我知道我可以手动更改线条样式。但我需要使用带有选择框的 streamlit 发布它,这意味着图中显示的列将被更改。所以这不是一个好的选择。

蟒蛇3.9.7;情节 5.3.1

4

0 回答 0