我正在尝试运行在here中找到的一些代码,作为进行某些财务分析的起点。我将代码稍作更改:
import matplotlib.pyplot as plt
import pandas as pd
import quandl as ql
yield_ = ql.get("USTREASURY/YIELD")
today = yield_.iloc[-1,:]
month_ago = yield_.iloc[-30,:]
df = pd.concat([today, month_ago], axis=1)
df.columns = ['today', 'month_ago']
df.plot(style={'today': 'ro-', 'month_ago': 'bx--'}
,title='Treasury Yield Curve, %');
plt.show(block=True)
plot.show行是导致此错误的原因,但是pyCharm需要实际显示该图,如here所示。该post描述了注册表项是如何导致该错误的,我怀疑这里是这种情况,但是我很困惑。有人可以提供一些有关我需要更改哪些键以及为什么实际发生错误的见解。我很好奇。
在pycharm中运行它时,出现此错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\David\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 1702, in __call__
return self.func(*args)
File "C:\Users\David\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\backends\_backend_tk.py", line 227, in resize
self.draw()
File "C:\Users\David\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 12, in draw
super(FigureCanvasTkAgg, self).draw()
File "C:\Users\David\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\backends\backend_agg.py", line 433, in draw
self.figure.draw(self.renderer)
File "C:\Users\David\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\David\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\figure.py", line 1475, in draw
renderer, self, artists, self.suppressComposite)
File "C:\Users\David\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\image.py", line 141, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\David\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\David\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\axes\_base.py", line 2607, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "C:\Users\David\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\image.py", line 141, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\David\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\David\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\axis.py", line 1192, in draw
renderer)
File "C:\Users\David\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\axis.py", line 1130, in _get_tick_bboxes
extent = tick.label1.get_window_extent(renderer)
File "C:\Users\David\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\text.py", line 922, in get_window_extent
bbox, info, descent = self._get_layout(self._renderer)
File "C:\Users\David\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\text.py", line 300, in _get_layout
ismath=False)
File "C:\Users\David\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\backends\backend_agg.py", line 241, in get_text_width_height_descent
font = self._get_agg_font(prop)
File "C:\Users\David\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\backends\backend_agg.py", line 275, in _get_agg_font
fname = findfont(prop)
File "C:\Users\David\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\font_manager.py", line 1475, in findfont
font = fontManager.findfont(prop, **kw)
File "C:\Users\David\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\font_manager.py", line 1350, in findfont
_rebuild()
File "C:\Users\David\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\font_manager.py", line 1454, in _rebuild
json_dump(fontManager, _fmcache)
File "C:\Users\David\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\font_manager.py", line 975, in json_dump
with open(filename, 'w') as fh:
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\David\\.matplotlib\\fontList.json'