选项按钮制图
I recently wanted to create a button for a plotly (the Python library) plot that exchanges the underlying data. I got stuck in the middle and since I couldn’t find much on Google, I thought it might be worth sharing this quick one with you.
我最近想为绘图(Python库)绘图创建一个按钮,以交换基础数据。 我被困在中间,由于我在Google上找不到很多东西,所以我认为值得与您快速分享这个内容。
A plotly plot can be updated by using passing updatemenus to the fig.update_layout()
method. In the plotly reference, we find that there are two ways (more precisely types) to update the data, dropdown and buttons. In this post, we go for buttons.
可以通过将updatemenus传递给fig.update_layout()
方法来更新绘图。 在可参考的参考资料中 ,我们发现有两种方法(更确切地说是类型)来更新数据: 下拉菜单和按钮 。 在这篇文章中,我们去寻找按钮。
There are four methods to change something in the plot by pressing the button: restyle, relayout, animate, and update. They determine which plotly.js function is called to modify the chart, in other words: what you can change in the plot. We want to modify the data but we might also need to adapt the corresponding axis labels, therefore, it is always sensible to go for update, which allows us to do both. Let’s create a data frame and a quick scatter plot to see how this works in action! Imagine you want to plot the relationship between temperature in degree Celsius and how many ice cream cones or drinks are sold per hour. After all, both should