Plotly doesn't provide a built in vectorization for such chart, because it can be done easily by yourself, see my example based on your provided links:import pandas as pdimport numpy as npimport plotly.offline as pyoimport plotly.graph_objs as go# Create a dataframevalue1 = np.random.uniform(size = 20)value2 = value1 + np.random.uniform(size = 20) / 4df = pd.DataFrame({'group':list(map(chr, range(65, 85))), 'value1':value1 , 'value2':value2 })my_range=range(1,len(df.index)+1)# Add title and axis namesdata1 = go.Scatter( x=df['value1'], y=np.array(my_range), mode='markers', marker=dict(color='blue') )data2 = go.Scatter( x=df['value2'], y=np.array(my_range), mode='markers', marker=dict(color='green') )# Horizontal line shapeshapes=[dict( type='line', x0 = df['value1'].loc[i], y0 = i + 1, x1 = df['value2'].loc[i], y1 = i + 1, line = dict( color = 'grey', width = 2 ) ) for i in range(len(df['value1']))]layout = go.Layout( shapes = shapes, title='Lollipop Chart')# Plot the chartfig = go.Figure([data1, data2], layout)pyo.plot(fig)结果我得到了: 这篇关于将线段添加到绘图中的简洁方法(使用python/jupyter笔记本)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-08 10:20