python - Python烛台图无法显示
问题描述
我执行了下面的代码,过程中没有显示错误,但是 plt.show() 无法工作,最后什么也没显示!我很困惑,想知道为什么......
from mpl_finance import candlestick_ohlc
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
import quandl
df = quandl.get("EOD/AAPL", authtoken="fzTPb-TWywaPkbdAS1VF")
df['Date'] = df.index.map(mdates.date2num)
ohlc = df[['Date','Open','High','Low','Close']]
f1, ax = plt.subplots(figsize = (10,5))
candlestick_ohlc(ax, ohlc.values, width=.6, colorup='green', colordown='red')
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m'))
plt.show()
解决方案
在 jupyter notebook 中,定义后端是有意义的,例如%matplotlib inline
or %matplotlib notebook
。然后在单个单元格中运行您的代码时,它应该向您显示该图。
如果您需要在单独的单元格中运行它,plt.show()
将不知道从以前的单元格中显示什么。因此,在这种情况下,请改为说明数字,
f1
显示图f1
。
推荐阅读
- r - R中数据框中的str替换和正则表达式匹配
- javascript - 如何触发从父组件到模态子组件的事件
- c - 某些内容未写入文件
- upwork-api - UpWork API 未正确找到实体
- javascript - 使用 React “useState”,当对象中的值更新时,即使某些值没有更改,也会重新渲染附加到状态的所有内容
- android - 实现浏览器选项卡
- azure - 如何使用 arm 模板在服务总线队列级别创建自定义共享访问策略
- css - React Strap Carousel Exit Animation 以显示
- c++ - 为什么 -O3 向下转换/更改对变量的 const 引用的值?
- r - 按组排列ggplot图例