python - 如何清除现金 go.Figure() 情节?
问题描述
我正在使用一个通用类,它可以绘制多个条形图堆叠或与 Plotly 分组。我的问题是我的函数也在我未来的图中使用旧数据,即使是我的__init__()
.
这是我的代码:
class multiple_bar_chart:
'''
This class allow the user to create a multiple bar chart (stack or group)
and add as many features as he wants.
/!\ X column must be in the same format for each new data
:param barmode : type of bar chart
=> add_bar : add a new bar to your plot
=> plot_plt : display your chart
'''
def __init__(self, figure=go.Figure(), barmode='stack'):
self.fig = figure
self.type_bar_chart = barmode # group or stacked
def add_bar(self, input_df, x_column, y_column, data_legend, color=None):
self.fig.add_bar(name=data_legend,
x=input_df[x_column],
y=input_df[y_column],
marker_color=color)
def plot_plt(self):
self.fig.update_layout(barmode=self.type_bar_chart)
st.markdown(download_plot(self.fig), unsafe_allow_html=True)
st.plotly_chart(self.fig, use_container_width=True)
plot1 = multiple_bar_chart(barmode = 'stack')
plot2 = multiple_bar_chart(barmode = 'group') # This class is also using the plot1 data
我知道我的问题来自go.Figure()
,但我不知道为什么我__init__()
没有初始化它。
有人有解决这个问题的想法吗?我将不胜感激!
另外,如果您对提高我的编程技能有一些建议,我正在倾听!:)
感谢,并有一个愉快的一天 :)
解决方案
推荐阅读
- javascript - 对象没有出现在组件 React Bootstrap/CSS 的中间
- javascript - 复选框中的 React-hook-form 自定义 onChange 处理程序->未注册更改
- python - 如何在 Pandas 中进行累积分组直到特定条件中断?
- swift - 需要变量作为参数/参数?
- visual-c++ - Visual c++ 在代码中禁用静态检查器
- javascript - 如何在 UI 路径中处理 google re-captcha v3
- c++ - 使用可用的编译指示优化 Vivado HLS 中的降噪算法
- mysql - Omitempty 字段不起作用,如何从响应正文中删除空结构?
- css - 制作自定义单选按钮css
- python - django 的 Azure SQL 数据库连接错误