我一直试图用相同的图例 colored颜色 和非重复的标签来绘制堆叠图,但没有太多成功.
import plotly.graph_objects as go
from plotly.subplots import make_subplots
# Sample data
x = [1, 2, 3, 4, 5]
y1 = [1, 2, 4, 8, 16]
y2 = [1, 3, 6, 10, 15]
y3 = [1, 4, 8, 12, 16]
# Create subplot figure with two subplots
fig = make_subplots(rows=1, cols=2, subplot_titles=('Subplot 1', 'Subplot 2'))
# Add stacked area plot to subplot 1
fig.add_trace(go.Scatter(x=x, y=y1, mode='lines', stackgroup='one', name='A'), row=1, col=1)
fig.add_trace(go.Scatter(x=x, y=y2, mode='lines', stackgroup='one', name='B'), row=1, col=1)
# Add stacked area plot to subplot 2
fig.add_trace(go.Scatter(x=x, y=y1, mode='lines', stackgroup='two', name='A'), row=1, col=2)
fig.add_trace(go.Scatter(x=x, y=y3, mode='lines', stackgroup='two', name='C'), row=1, col=2)
# Update layout
fig.update_layout(title_text='Stacked Area Plots on Subplots', showlegend=True)
# Show figure
fig.show()
结果图如下:
如有任何帮助,我们不胜感激.