Plotly Chart at Tkinter Python(在 Tkinter Python 绘制图表)
问题描述
是否可以在 Tkinter GUI 上显示 Plotly 图表?我一直试图让这种情况发生,但无济于事.
is it possible to show Plotly chart at Tkinter GUI? I have been trying to make this happens but to no avail.
这是我的代码(Plotly 代码是从 Plotly 网站复制的):
Here is the code I have (the Plotly code is copied from the Plotly website):
from tkinter import *
import plotly.plotly as py
import plotly.graph_objs as go
from datetime import datetime
import pandas.io.data as web
mGui = Tk()
mGui.geometry('651x700+51+51')
mGui.title('Plotly at Tkinter')
df = web.DataReader("AAPL", 'yahoo',
datetime(2007, 10, 1),
datetime(2016, 7, 11))
trace = go.Scatter(x=df.index,
y=df.High)
data = [trace]
layout = dict(
title="VGltZSBzZXJpZXMgd2l0aCByYW5nZSBzbGlkZXIgYW5kIHNlbGVjdG9ycw==",
xaxis=dict(
rangeselector=dict(
buttons=list([
dict(count=1,
label='1m',
step='month',
stepmode='backward'),
dict(count=6,
label='6m',
step='month',
stepmode='backward'),
dict(count=1,
label='YTD',
step='year',
stepmode='todate'),
dict(count=1,
label='1y',
step='year',
stepmode='backward'),
dict(step='all')
])
),
rangeslider=dict(),
type='date'
)
)
fig = dict(data=data, layout=layout)
py.iplot(fig)
mGui.mainloop()
提前谢谢你.
推荐答案
根据:https://plotly.com/python/renderers/可用的绘图渲染器是:
According to: https://plotly.com/python/renderers/ The available plotly renderers are:
['plotly_mimetype', 'jupyterlab', 'nteract', 'vscode',
'notebook', 'notebook_connected', 'kaggle', 'azure', 'colab',
'cocalc', 'databricks', 'json', 'png', 'jpeg', 'jpg', 'svg',
'pdf', 'browser', 'firefox', 'chrome', 'chromium', 'iframe',
'iframe_connected', 'sphinx_gallery']
这意味着不可能让 tkinter 直接处理情节用户交互事件.因此,最接近您想要的是生成非交互式绘图渲染,例如 png/jpg 并将其显示在 tkinter 画布中.至少画布将允许平移/扫描和缩放.另一种选择是从 tkinter 应用程序打开网络浏览器,但这意味着用户不会直接与原始 tkinter 应用程序进行交互.
This means that it is not possible to have tkinter directly handle plotly user interactive events. The closest to what you want would hence be to generate a non interactive plotly rendering eg a png/jpg and display it in a tkinter canvas. At least canvas would allow to pan/scan and zoom. Another alternative would be to open a web browser from the tkinter app but this means user will not directly interact with the original tkinter application.
这篇关于在 Tkinter Python 绘制图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Tkinter Python 绘制图表


- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01