python - 如何在不重新生成图形的情况下离线使用情节?
问题描述
目前,我正在像这样离线使用情节:
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWidgets import *
import plotly.graph_objects as go
import plotly
import numpy as np
class Window(QWidget):
def __init__(self):
super(Window, self).__init__()
grid_layout = QGridLayout()
self.pb = QPushButton('plot')
# some example data
x = np.arange(0, 2*np.pi, 0.001)
y = np.sin(x)
# create the plotly figure
fig = go.Figure(go.Scatter(x=x, y=y))
# we create html code of the figure
html = "".join(['<html><body>',
plotly.offline.plot(fig, output_type='div', include_plotlyjs='cdn'),
'</body></html>']
)
# we create an instance of QWebEngineView and set the html code
self.plot_widget = QWebEngineView()
self.plot_widget.setHtml(html)
grid_layout.addWidget(self.plot_widget, 0, 0)
grid_layout.addWidget(self.pb, 1, 0)
self.setLayout(grid_layout)
self.pb.clicked.connect(self.newplot)
def newplot(self):
# some example data
x = np.arange(0, 2 * np.pi, 0.001)
y = np.sin(x+np.random.uniform(low=0, high=2*np.pi))
# create the plotly figure
fig = go.Figure(go.Scatter(x=x, y=y))
# we create html code of the figure
html = "".join(['<html><body>',
plotly.offline.plot(fig, output_type='div', include_plotlyjs='cdn'),
'</body></html>']
)
self.plot_widget.setHtml(html)
if __name__ == '__main__':
app = QApplication([])
window = Window()
window.show()
app.exec_()
我的问题是,这样当我画一个新的情节时,整个事情都会重新生成。有没有办法更顺利地做到这一点,只更新现有的数字?保留轴,并在图中用新线替换旧线。
解决方案
我已经使用 Plotly for Python 一年多了,但我从未听说过你描述的可能性。
推荐阅读
- c++ - 使用自定义 less 运算符实现迭代 std::map 会减少它包含的元素
- javascript - 检查猫鼬模型是否有空属性
- r - 如何在 r 中避免这种 for 循环
- mysql - JetBrains 无法连接托管 MySQL 数据库
- jquery - Select2:数据在不选择选项时显示?
- moq - 如何使用 AutoFixture 和 AutoMoqCustomization 设置某些属性并将其他属性保留为默认值?
- javascript - 调整在 d3.js 图中绘制的图的大小
- flutter - 如何从 firebase_messaging 推送通知中获取时间?
- django - Django 'app' 等于 Angular 中的 'component' 吗?
- android - 我给一个人一个 apk,Xamarin 为分发创建的版本有什么区别?