Python:绘图图不渲染
我正在尝试使用Python 3.9(Anaconda/Spyder)中的Plotly绘制股票价格,但图并未显示。以下代码执行没有错误,但没有图。
import yfinance
tsla = yfinance.Ticker('TSLA')
hist = tsla.history(period='1y')
import plotly.graph_objects as go
fig = go.Figure(data=go.Scatter(x=hist.index,y=hist['Close'], mode='lines'))
fig.show()
我正在研究本地版的Python,没有网络交互。 以下代码可用于在浏览器窗口中绘制:
import plotly.express as px
fig = px.bar(x=["a", "b", "c"], y=[1, 3, 2])
fig.write_html('first_figure.html', auto_open=True)
不确定为什么.show()不起作用。似乎是最基本的功能。 希望我缺少一些简单/显而易见的东西。
I'm trying to plot a stock price using Plotly in Python 3.9 (Anaconda/Spyder), but the graph isn't displaying. The following code executes without error, but no plot.
import yfinance
tsla = yfinance.Ticker('TSLA')
hist = tsla.history(period='1y')
import plotly.graph_objects as go
fig = go.Figure(data=go.Scatter(x=hist.index,y=hist['Close'], mode='lines'))
fig.show()
I'm working on local version of Python, no web interaction.
The following code works for plotting in a browser window:
import plotly.express as px
fig = px.bar(x=["a", "b", "c"], y=[1, 3, 2])
fig.write_html('first_figure.html', auto_open=True)
Just not sure why .show() isn't working. Seems to be the most basic function there is to Plotly.
Hoping there's something easy/obvious I'm missing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试添加以下内容:
它将在默认浏览器中打开图。
有关 Renderers 的更多信息
Try adding this :
It will open the plot in your default browser.
More info on renderers