如何为具有多个 y 轴的图表制作动画 (python)
How to animate chart with multiple y axis (python)
我正在尝试制作带有辅助 y 轴的动画图(目前使用 plotly.express 但对任何其他解决方案开放)。我已经阅读了关于如何使用多个组制作条形图动画的不同帖子 () and make second axis on plotly-express (Plotly: How to plot on secondary y-Axis with plotly express),但是我还没有找到任何关于如何使用第二个 y 轴制作动画图的答案。
这是我的代码
import pandas as pd
import plotly.express as px
df = pd.read_csv("plotly_animation_Whosebug.csv")
px.bar(data_frame=df,x="date",y=["A","B","C"],animation_frame="lag",barmode="group")
而且由于比例问题,我看不到 C 列的条形图
plotly-express 也存在问题,因为我的数据框扩展时会出现额外的滞后。我可以在 Tableau 中轻松地做到这一点,但我正在努力保持这个开源。有没有另一种方法可以将函数传递给绘图,它会在我移动滑动条时应用额外的滞后?
这是数据
date,A,B,C,lag
8/22/2016,54987,36488,0.3389,0
8/23/2016,91957,73793,0.3389,0
8/24/2016,91957,73793,0.3357,0
8/25/2016,91957,73793,0.3291,0
8/26/2016,91957,73793,0.3295,0
8/29/2016,91957,73793,0.3281,0
8/30/2016,107657,82877,0.3273,0
8/31/2016,107657,82877,0.3247,0
9/1/2016,107657,82877,0.322,0
9/2/2016,107657,82877,0.3266,0
8/22/2016,54987,36488,NA,1
8/23/2016,91957,73793,0.3389,1
8/24/2016,91957,73793,0.3389,1
8/25/2016,91957,73793,0.3357,1
8/26/2016,91957,73793,0.3291,1
8/29/2016,91957,73793,0.3295,1
8/30/2016,107657,82877,0.3281,1
8/31/2016,107657,82877,0.3273,1
9/1/2016,107657,82877,0.3247,1
9/2/2016,107657,82877,0.322,1
9/3/2016,,,0.3266,1
8/22/2016,54987,36488,,2
8/23/2016,91957,73793,,2
8/24/2016,91957,73793,0.3389,2
8/25/2016,91957,73793,0.3389,2
8/26/2016,91957,73793,0.3357,2
8/29/2016,91957,73793,0.3291,2
8/30/2016,107657,82877,0.3295,2
8/31/2016,107657,82877,0.3281,2
9/1/2016,107657,82877,0.3273,2
9/2/2016,107657,82877,0.3247,2
9/3/2016,,,0.322,2
9/4/2016,,,0.3266,2
- 构建图形后,更新所需的轨迹以使用次要 y 轴。这需要包括框架内的痕迹以及图中的痕迹
- 配置辅助 y 轴
import pandas as pd
import plotly.express as px
import io
data = """date,A,B,C,lag
8/22/2016,54987,36488,0.3389,0
8/23/2016,91957,73793,0.3389,0
8/24/2016,91957,73793,0.3357,0
8/25/2016,91957,73793,0.3291,0
8/26/2016,91957,73793,0.3295,0
8/29/2016,91957,73793,0.3281,0
8/30/2016,107657,82877,0.3273,0
8/31/2016,107657,82877,0.3247,0
9/1/2016,107657,82877,0.322,0
9/2/2016,107657,82877,0.3266,0
8/22/2016,54987,36488,NA,1
8/23/2016,91957,73793,0.3389,1
8/24/2016,91957,73793,0.3389,1
8/25/2016,91957,73793,0.3357,1
8/26/2016,91957,73793,0.3291,1
8/29/2016,91957,73793,0.3295,1
8/30/2016,107657,82877,0.3281,1
8/31/2016,107657,82877,0.3273,1
9/1/2016,107657,82877,0.3247,1
9/2/2016,107657,82877,0.322,1
9/3/2016,,,0.3266,1
8/22/2016,54987,36488,,2
8/23/2016,91957,73793,,2
8/24/2016,91957,73793,0.3389,2
8/25/2016,91957,73793,0.3389,2
8/26/2016,91957,73793,0.3357,2
8/29/2016,91957,73793,0.3291,2
8/30/2016,107657,82877,0.3295,2
8/31/2016,107657,82877,0.3281,2
9/1/2016,107657,82877,0.3273,2
9/2/2016,107657,82877,0.3247,2
9/3/2016,,,0.322,2
9/4/2016,,,0.3266,2"""
df = pd.read_csv(io.StringIO(data))
fig = px.bar(data_frame=df,x="date",y=["A","B","C"],animation_frame="lag",barmode="group")
# update approprate traces to use secondary yaxis
for t in fig.data:
if t.name=="C": t.update(yaxis="y2")
for f in fig.frames:
for t in f.data:
if t.name=="C": t.update(yaxis="y2")
# configure yaxis2 and give it some space
fig.update_layout(yaxis2={"overlaying":"y", "side":"right"}, xaxis={"domain":[0,.98]})
我正在尝试制作带有辅助 y 轴的动画图(目前使用 plotly.express 但对任何其他解决方案开放)。我已经阅读了关于如何使用多个组制作条形图动画的不同帖子 (
这是我的代码
import pandas as pd
import plotly.express as px
df = pd.read_csv("plotly_animation_Whosebug.csv")
px.bar(data_frame=df,x="date",y=["A","B","C"],animation_frame="lag",barmode="group")
而且由于比例问题,我看不到 C 列的条形图
plotly-express 也存在问题,因为我的数据框扩展时会出现额外的滞后。我可以在 Tableau 中轻松地做到这一点,但我正在努力保持这个开源。有没有另一种方法可以将函数传递给绘图,它会在我移动滑动条时应用额外的滞后?
这是数据
date,A,B,C,lag
8/22/2016,54987,36488,0.3389,0
8/23/2016,91957,73793,0.3389,0
8/24/2016,91957,73793,0.3357,0
8/25/2016,91957,73793,0.3291,0
8/26/2016,91957,73793,0.3295,0
8/29/2016,91957,73793,0.3281,0
8/30/2016,107657,82877,0.3273,0
8/31/2016,107657,82877,0.3247,0
9/1/2016,107657,82877,0.322,0
9/2/2016,107657,82877,0.3266,0
8/22/2016,54987,36488,NA,1
8/23/2016,91957,73793,0.3389,1
8/24/2016,91957,73793,0.3389,1
8/25/2016,91957,73793,0.3357,1
8/26/2016,91957,73793,0.3291,1
8/29/2016,91957,73793,0.3295,1
8/30/2016,107657,82877,0.3281,1
8/31/2016,107657,82877,0.3273,1
9/1/2016,107657,82877,0.3247,1
9/2/2016,107657,82877,0.322,1
9/3/2016,,,0.3266,1
8/22/2016,54987,36488,,2
8/23/2016,91957,73793,,2
8/24/2016,91957,73793,0.3389,2
8/25/2016,91957,73793,0.3389,2
8/26/2016,91957,73793,0.3357,2
8/29/2016,91957,73793,0.3291,2
8/30/2016,107657,82877,0.3295,2
8/31/2016,107657,82877,0.3281,2
9/1/2016,107657,82877,0.3273,2
9/2/2016,107657,82877,0.3247,2
9/3/2016,,,0.322,2
9/4/2016,,,0.3266,2
- 构建图形后,更新所需的轨迹以使用次要 y 轴。这需要包括框架内的痕迹以及图中的痕迹
- 配置辅助 y 轴
import pandas as pd
import plotly.express as px
import io
data = """date,A,B,C,lag
8/22/2016,54987,36488,0.3389,0
8/23/2016,91957,73793,0.3389,0
8/24/2016,91957,73793,0.3357,0
8/25/2016,91957,73793,0.3291,0
8/26/2016,91957,73793,0.3295,0
8/29/2016,91957,73793,0.3281,0
8/30/2016,107657,82877,0.3273,0
8/31/2016,107657,82877,0.3247,0
9/1/2016,107657,82877,0.322,0
9/2/2016,107657,82877,0.3266,0
8/22/2016,54987,36488,NA,1
8/23/2016,91957,73793,0.3389,1
8/24/2016,91957,73793,0.3389,1
8/25/2016,91957,73793,0.3357,1
8/26/2016,91957,73793,0.3291,1
8/29/2016,91957,73793,0.3295,1
8/30/2016,107657,82877,0.3281,1
8/31/2016,107657,82877,0.3273,1
9/1/2016,107657,82877,0.3247,1
9/2/2016,107657,82877,0.322,1
9/3/2016,,,0.3266,1
8/22/2016,54987,36488,,2
8/23/2016,91957,73793,,2
8/24/2016,91957,73793,0.3389,2
8/25/2016,91957,73793,0.3389,2
8/26/2016,91957,73793,0.3357,2
8/29/2016,91957,73793,0.3291,2
8/30/2016,107657,82877,0.3295,2
8/31/2016,107657,82877,0.3281,2
9/1/2016,107657,82877,0.3273,2
9/2/2016,107657,82877,0.3247,2
9/3/2016,,,0.322,2
9/4/2016,,,0.3266,2"""
df = pd.read_csv(io.StringIO(data))
fig = px.bar(data_frame=df,x="date",y=["A","B","C"],animation_frame="lag",barmode="group")
# update approprate traces to use secondary yaxis
for t in fig.data:
if t.name=="C": t.update(yaxis="y2")
for f in fig.frames:
for t in f.data:
if t.name=="C": t.update(yaxis="y2")
# configure yaxis2 and give it some space
fig.update_layout(yaxis2={"overlaying":"y", "side":"right"}, xaxis={"domain":[0,.98]})