Plotly - 填充三行之间的区域 - 如何删除这个暗影
Plotly - Fill area between three lines - How do I remove this dark shadows
fig = go.Figure(layout_yaxis_range=[0,10])
fig.add_traces(go.Scatter(
x=df['date'],
y=df['25 Percentile'],
name = '25th Percentile',
mode='text',
line=dict(color='blue'),
fill='tonext',
fillcolor='grey',
connectgaps=False
))
fig.add_traces(go.Scatter(
x=df['date'],
y=df['Median'],
name = 'Median',
mode='lines',
line=dict(color='green'),
fill='tonexty',
fillcolor='#eaecee',
connectgaps=False
))
fig.add_traces(go.Scatter(
x=df['date'],
y=df['75 Percentile'],
name = '75th Percentile',
mode='text',
line=dict(color='blue'),
fill='tonexty',
fillcolor='#eaecee',
connectgaps=False
))
fig.update_layout(template='plotly_white')
fig.show()
我正在尝试填充三行之间的区域但是无法摆脱这个暗影。
我试图通过将其更改为所有可用值来确保 fill='' 参数正确,但不确定哪个有效。
如何去除这个暗影?
谢谢!
- 有模拟数据可以re-produce
- 你的代码有两个问题
- 两条轨迹被定义为
mode="text"
已更改为 mode="lines"
- 只需要
fill="tonexty"
百分位轨迹
import plotly.graph_objects as go
import pandas as pd
import numpy as np
df = pd.DataFrame({"date": pd.date_range("30-mar-2022", "15-may-2022")}).assign(
val=lambda d: np.random.randint(1, 10, len(d))
)
df = df.join(
df["val"]
.rolling(5)
.agg(["median", lambda w: np.percentile(w, 25), lambda w: np.percentile(w, 75)])
).dropna()
df.columns = ["date", "val", "Median", "25 Percentile", "75 Percentile"]
fig = go.Figure(layout_yaxis_range=[0, 10])
fig.add_traces(
go.Scatter(
x=df["date"],
y=df["25 Percentile"],
name="25th Percentile",
mode="lines",
line=dict(color="blue"),
# fill='tonext',
# fillcolor='grey',
connectgaps=False,
)
)
fig.add_traces(
go.Scatter(
x=df["date"],
y=df["Median"],
name="Median",
mode="lines",
line=dict(color="green"),
fill="tonexty",
fillcolor="#eaecee",
connectgaps=False,
)
)
fig.add_traces(
go.Scatter(
x=df["date"],
y=df["75 Percentile"],
name="75th Percentile",
mode="lines",
line=dict(color="blue"),
fill="tonexty",
fillcolor="#eaecee",
connectgaps=False,
)
)
fig.update_layout(template="plotly_white")
fig.show()
fig = go.Figure(layout_yaxis_range=[0,10])
fig.add_traces(go.Scatter(
x=df['date'],
y=df['25 Percentile'],
name = '25th Percentile',
mode='text',
line=dict(color='blue'),
fill='tonext',
fillcolor='grey',
connectgaps=False
))
fig.add_traces(go.Scatter(
x=df['date'],
y=df['Median'],
name = 'Median',
mode='lines',
line=dict(color='green'),
fill='tonexty',
fillcolor='#eaecee',
connectgaps=False
))
fig.add_traces(go.Scatter(
x=df['date'],
y=df['75 Percentile'],
name = '75th Percentile',
mode='text',
line=dict(color='blue'),
fill='tonexty',
fillcolor='#eaecee',
connectgaps=False
))
fig.update_layout(template='plotly_white')
fig.show()
我正在尝试填充三行之间的区域但是无法摆脱这个暗影。 我试图通过将其更改为所有可用值来确保 fill='' 参数正确,但不确定哪个有效。
如何去除这个暗影?
谢谢!
- 有模拟数据可以re-produce
- 你的代码有两个问题
- 两条轨迹被定义为
mode="text"
已更改为mode="lines"
- 只需要
fill="tonexty"
百分位轨迹
- 两条轨迹被定义为
import plotly.graph_objects as go
import pandas as pd
import numpy as np
df = pd.DataFrame({"date": pd.date_range("30-mar-2022", "15-may-2022")}).assign(
val=lambda d: np.random.randint(1, 10, len(d))
)
df = df.join(
df["val"]
.rolling(5)
.agg(["median", lambda w: np.percentile(w, 25), lambda w: np.percentile(w, 75)])
).dropna()
df.columns = ["date", "val", "Median", "25 Percentile", "75 Percentile"]
fig = go.Figure(layout_yaxis_range=[0, 10])
fig.add_traces(
go.Scatter(
x=df["date"],
y=df["25 Percentile"],
name="25th Percentile",
mode="lines",
line=dict(color="blue"),
# fill='tonext',
# fillcolor='grey',
connectgaps=False,
)
)
fig.add_traces(
go.Scatter(
x=df["date"],
y=df["Median"],
name="Median",
mode="lines",
line=dict(color="green"),
fill="tonexty",
fillcolor="#eaecee",
connectgaps=False,
)
)
fig.add_traces(
go.Scatter(
x=df["date"],
y=df["75 Percentile"],
name="75th Percentile",
mode="lines",
line=dict(color="blue"),
fill="tonexty",
fillcolor="#eaecee",
connectgaps=False,
)
)
fig.update_layout(template="plotly_white")
fig.show()