Python Can';jupyter笔记本中的t绘图
我有一个jupyter笔记本脚本,其中一部分看起来像:Python Can';jupyter笔记本中的t绘图,python,pandas,jupyter-notebook,latex,Python,Pandas,Jupyter Notebook,Latex,我有一个jupyter笔记本脚本,其中一部分看起来像: import pandas as pd import matplotlib import matplotlib.pyplot as plt import numpy as np %matplotlib inline matplotlib.style.use('ggplot') matplotlib.rc('text', usetex=True) import scipy.stats df = pd.read_csv("./titan
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
matplotlib.style.use('ggplot')
matplotlib.rc('text', usetex=True)
import scipy.stats
df = pd.read_csv("./titanic-train.csv")
ax = df.Age.hist(bins=20)
ax.set_xlabel("age / years")
ax.set_ylabel("frequency");
之后,我得到一个错误,它不会打印直方图。
我使用的是与Anaconda一起安装的Python 3.7.3。
通过在Windows 10的cmd窗口中打印latex,我得到:
这是pdfTeX,版本3.14159265-2.6-1.40.20(MiKTeX 2.9.7250
(64位)
下面是运行dataframe.hist()时得到的错误消息:
回调中的错误(用于post_执行):
---------------------------------------------------------------------------
FileNotFoundError回溯(最近一次调用上次)
子流程(self、command、tex)中的~\Anaconda3\lib\site packages\matplotlib\texmanager.py
303 cwd=self.texcache,
-->304 stderr=子流程(STDOUT)
305除FileNotFoundError作为exc外:
检查输出中的~\Anaconda3\lib\subprocess.py(超时,*popenargs,**kwargs)
394返回运行(*popenargs,stdout=PIPE,timeout=timeout,check=True,
-->395**kwargs)标准件
396
运行中的~\Anaconda3\lib\subprocess.py(输入、捕获输出、超时、检查、*popenargs、**kwargs)
471
-->472以Popen(*popenargs,**kwargs)为流程:
473试试:
初始化中的~\Anaconda3\lib\subprocess.py(self、args、bufsize、executable、stdin、stdout、stderr、preexec\fn、close\fds、shell、cwd、env、universal\u换行符、startupinfo、creationflags、restore\u信号、start\u new\u会话、pass\fds、编码、错误、文本)
774错误读取,错误写入,
-->775恢复信号,启动新会话)
776除:
执行子进程中的~\Anaconda3\lib\subprocess.py(self、args、executable、preexec\u fn、close\u fds、pass\u fds、cwd、env、startupinfo、creationflags、shell、p2cread、p2cwrite、c2pread、c2pwrite、errread、errwrite、未使用的恢复信号、未使用的启动新会话)
1177 os.fspath(cwd)如果cwd不是None-else-None,
->1178(创业信息)
1179最后:
FileNotFoundError:[WinError 2]系统找不到指定的文件
上述异常是以下异常的直接原因:
运行时错误回溯(上次最近调用)
post\u execute()中的~\Anaconda3\lib\site packages\matplotlib\pyplot.py
107 def post_execute():
108如果matplotlib.is_interactive():
-->109抽签
110
111#IPython>=2
绘图中的~\Anaconda3\lib\site packages\matplotlib\\u pylab\u helpers.py(cls,force)
126用于cls中的f_经理。获取所有图_经理()
127如果强制或f_mgr.canvas.figure.stale:
-->128 f_mgr.canvas.draw_idle()
129
130 atexit.寄存器(Gcf.销毁所有)
~\Anaconda3\lib\site packages\matplotlib\backend\u bases.py in draw\u idle(self,*args,**kwargs)
1905如果不是自己,则为空闲图纸:
1906年,使用self.\u idle\u draw\u cntx():
->1907年自绘(*args,**kwargs)
1908
1909 def draw_光标(自身、事件):
~\Anaconda3\lib\site packages\matplotlib\backends\backend\u agg.py in draw(self)
386 self.renderer=self.get\u渲染器(清除=True)
387带有renderragg.lock:
-->388 self.figure.draw(self.renderer)
389#可能需要GUI类使用此绘图更新窗口,因此
别忘了调用超类。
绘图包装中的~\Anaconda3\lib\site packages\matplotlib\artist.py(艺术家、渲染器、*args、**kwargs)
36.start_filter()
37
--->38返回绘制(艺术家、渲染器、*args、**kwargs)
39.最后:
40如果artist.get_agg_filter()不是无:
绘图中的~\Anaconda3\lib\site packages\matplotlib\figure.py(自身,渲染器)
1707自补片绘制(渲染器)
1708模拟图像。\绘制\列表\合成\图像(
->1709渲染器,自我,艺术家,自我(合成)
1710
1711.关闭_组(“图”)
~\Anaconda3\lib\site packages\matplotlib\image.py位于\u draw\u list\u compositing\u图像(渲染器、父级、艺术家、抑制合成)中
133如果没有\u复合或没有\u图像:
134对于一个艺术家:
-->135 a.draw(渲染器)
136.其他:
137#将任何相邻图像合成在一起
绘图包装中的~\Anaconda3\lib\site packages\matplotlib\artist.py(艺术家、渲染器、*args、**kwargs)
36.start_filter()
37
--->38返回绘制(艺术家、渲染器、*args、**kwargs)
39.最后:
40如果artist.get_agg_filter()不是无:
绘图中的~\Anaconda3\lib\site packages\matplotlib\axes\\u base.py(self、渲染器、inframe)
2643渲染器。停止网格化()
2644
->2645模拟图像。\绘制\列表\合成\图像(渲染器、自身、艺术家)
2646
2647渲染器。关闭_组(“轴”)
~\Anaconda3\lib\site packages\matplotlib\image.py位于\u draw\u list\u compositing\u图像(渲染器、父级、艺术家、抑制合成)中
133如果没有\u复合或没有\u图像:
134对于一个艺术家:
-->135 a.draw(渲染器)
136.其他:
137#将任何相邻图像合成在一起
绘图包装中的~\Anaconda3\lib\site packages\matplotlib\artist.py(艺术家、渲染器、*args、**kwargs)
36.start_filter()
37
--->38返回绘制(艺术家、渲染器、*args、**kwargs)
39.最后:
40如果artist.get_agg_filter()不是无:
绘图中的~\Anaconda3\lib\site packages\matplotlib\axis.py(self、renderer、*args、**kwargs)
1204勾号到勾号=self.\u更新勾号()
1205勾选框,勾选框2=自身。
Error in callback <function install_repl_displayhook.<locals>.post_execute at 0x0000029D82BD2950> (for post_execute):
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\matplotlib\texmanager.py in _run_checked_subprocess(self, command, tex)
303 cwd=self.texcache,
--> 304 stderr=subprocess.STDOUT)
305 except FileNotFoundError as exc:
~\Anaconda3\lib\subprocess.py in check_output(timeout, *popenargs, **kwargs)
394 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
--> 395 **kwargs).stdout
396
~\Anaconda3\lib\subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
471
--> 472 with Popen(*popenargs, **kwargs) as process:
473 try:
~\Anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
774 errread, errwrite,
--> 775 restore_signals, start_new_session)
776 except:
~\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
1177 os.fspath(cwd) if cwd is not None else None,
-> 1178 startupinfo)
1179 finally:
FileNotFoundError: [WinError 2] The system cannot find the file specified
The above exception was the direct cause of the following exception:
RuntimeError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\matplotlib\pyplot.py in post_execute()
107 def post_execute():
108 if matplotlib.is_interactive():
--> 109 draw_all()
110
111 # IPython >= 2
~\Anaconda3\lib\site-packages\matplotlib\_pylab_helpers.py in draw_all(cls, force)
126 for f_mgr in cls.get_all_fig_managers():
127 if force or f_mgr.canvas.figure.stale:
--> 128 f_mgr.canvas.draw_idle()
129
130 atexit.register(Gcf.destroy_all)
~\Anaconda3\lib\site-packages\matplotlib\backend_bases.py in draw_idle(self, *args, **kwargs)
1905 if not self._is_idle_drawing:
1906 with self._idle_draw_cntx():
-> 1907 self.draw(*args, **kwargs)
1908
1909 def draw_cursor(self, event):
~\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in draw(self)
386 self.renderer = self.get_renderer(cleared=True)
387 with RendererAgg.lock:
--> 388 self.figure.draw(self.renderer)
389 # A GUI class may be need to update a window using this draw, so
390 # don't forget to call the superclass.
~\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
36 renderer.start_filter()
37
---> 38 return draw(artist, renderer, *args, **kwargs)
39 finally:
40 if artist.get_agg_filter() is not None:
~\Anaconda3\lib\site-packages\matplotlib\figure.py in draw(self, renderer)
1707 self.patch.draw(renderer)
1708 mimage._draw_list_compositing_images(
-> 1709 renderer, self, artists, self.suppressComposite)
1710
1711 renderer.close_group('figure')
~\Anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
133 if not_composite or not has_images:
134 for a in artists:
--> 135 a.draw(renderer)
136 else:
137 # Composite any adjacent images together
~\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
36 renderer.start_filter()
37
---> 38 return draw(artist, renderer, *args, **kwargs)
39 finally:
40 if artist.get_agg_filter() is not None:
~\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in draw(self, renderer, inframe)
2643 renderer.stop_rasterizing()
2644
-> 2645 mimage._draw_list_compositing_images(renderer, self, artists)
2646
2647 renderer.close_group('axes')
~\Anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
133 if not_composite or not has_images:
134 for a in artists:
--> 135 a.draw(renderer)
136 else:
137 # Composite any adjacent images together
~\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
36 renderer.start_filter()
37
---> 38 return draw(artist, renderer, *args, **kwargs)
39 finally:
40 if artist.get_agg_filter() is not None:
~\Anaconda3\lib\site-packages\matplotlib\axis.py in draw(self, renderer, *args, **kwargs)
1204 ticks_to_draw = self._update_ticks()
1205 ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
-> 1206 renderer)
1207
1208 for tick in ticks_to_draw:
~\Anaconda3\lib\site-packages\matplotlib\axis.py in _get_tick_bboxes(self, ticks, renderer)
1149 """Return lists of bboxes for ticks' label1's and label2's."""
1150 return ([tick.label1.get_window_extent(renderer)
-> 1151 for tick in ticks if tick.label1.get_visible()],
1152 [tick.label2.get_window_extent(renderer)
1153 for tick in ticks if tick.label2.get_visible()])
~\Anaconda3\lib\site-packages\matplotlib\axis.py in <listcomp>(.0)
1149 """Return lists of bboxes for ticks' label1's and label2's."""
1150 return ([tick.label1.get_window_extent(renderer)
-> 1151 for tick in ticks if tick.label1.get_visible()],
1152 [tick.label2.get_window_extent(renderer)
1153 for tick in ticks if tick.label2.get_visible()])
~\Anaconda3\lib\site-packages\matplotlib\text.py in get_window_extent(self, renderer, dpi)
888 raise RuntimeError('Cannot get window extent w/o renderer')
889
--> 890 bbox, info, descent = self._get_layout(self._renderer)
891 x, y = self.get_unitless_position()
892 x, y = self.get_transform().transform_point((x, y))
~\Anaconda3\lib\site-packages\matplotlib\text.py in _get_layout(self, renderer)
289 _, lp_h, lp_d = renderer.get_text_width_height_descent(
290 "lp", self._fontproperties,
--> 291 ismath="TeX" if self.get_usetex() else False)
292 min_dy = (lp_h - lp_d) * self._linespacing
293
~\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in get_text_width_height_descent(self, s, prop, ismath)
199 fontsize = prop.get_size_in_points()
200 w, h, d = texmanager.get_text_width_height_descent(
--> 201 s, fontsize, renderer=self)
202 return w, h, d
203
~\Anaconda3\lib\site-packages\matplotlib\texmanager.py in get_text_width_height_descent(self, tex, fontsize, renderer)
446 else:
447 # use dviread. It sometimes returns a wrong descent.
--> 448 dvifile = self.make_dvi(tex, fontsize)
449 with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:
450 page, = dvi
~\Anaconda3\lib\site-packages\matplotlib\texmanager.py in make_dvi(self, tex, fontsize)
336 self._run_checked_subprocess(
337 ["latex", "-interaction=nonstopmode", "--halt-on-error",
--> 338 texfile], tex)
339 for fname in glob.glob(basefile + '*'):
340 if not fname.endswith(('dvi', 'tex')):
~\Anaconda3\lib\site-packages\matplotlib\texmanager.py in _run_checked_subprocess(self, command, tex)
306 raise RuntimeError(
307 'Failed to process string with tex because {} could not be '
--> 308 'found'.format(command[0])) from exc
309 except subprocess.CalledProcessError as exc:
310 raise RuntimeError(
RuntimeError: Failed to process string with tex because latex could not be found
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\matplotlib\texmanager.py in _run_checked_subprocess(self, command, tex)
303 cwd=self.texcache,
--> 304 stderr=subprocess.STDOUT)
305 except FileNotFoundError as exc:
~\Anaconda3\lib\subprocess.py in check_output(timeout, *popenargs, **kwargs)
394 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
--> 395 **kwargs).stdout
396
~\Anaconda3\lib\subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
471
--> 472 with Popen(*popenargs, **kwargs) as process:
473 try:
~\Anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
774 errread, errwrite,
--> 775 restore_signals, start_new_session)
776 except:
~\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
1177 os.fspath(cwd) if cwd is not None else None,
-> 1178 startupinfo)
1179 finally:
FileNotFoundError: [WinError 2] The system cannot find the file specified
The above exception was the direct cause of the following exception:
RuntimeError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
339 pass
340 else:
--> 341 return printer(obj)
342 # Finally look for special method names
343 method = get_real_method(obj, self.print_method)
~\Anaconda3\lib\site-packages\IPython\core\pylabtools.py in <lambda>(fig)
242
243 if 'png' in formats:
--> 244 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
245 if 'retina' in formats or 'png2x' in formats:
246 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
~\Anaconda3\lib\site-packages\IPython\core\pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
126
127 bytes_io = BytesIO()
--> 128 fig.canvas.print_figure(bytes_io, **kw)
129 data = bytes_io.getvalue()
130 if fmt == 'svg':
~\Anaconda3\lib\site-packages\matplotlib\backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, **kwargs)
2054 orientation=orientation,
2055 dryrun=True,
-> 2056 **kwargs)
2057 renderer = self.figure._cachedRenderer
2058 bbox_artists = kwargs.pop("bbox_extra_artists", None)
~\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in print_png(self, filename_or_obj, metadata, pil_kwargs, *args, **kwargs)
525
526 else:
--> 527 FigureCanvasAgg.draw(self)
528 renderer = self.get_renderer()
529 with cbook._setattr_cm(renderer, dpi=self.figure.dpi), \
~\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in draw(self)
386 self.renderer = self.get_renderer(cleared=True)
387 with RendererAgg.lock:
--> 388 self.figure.draw(self.renderer)
389 # A GUI class may be need to update a window using this draw, so
390 # don't forget to call the superclass.
~\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
36 renderer.start_filter()
37
---> 38 return draw(artist, renderer, *args, **kwargs)
39 finally:
40 if artist.get_agg_filter() is not None:
~\Anaconda3\lib\site-packages\matplotlib\figure.py in draw(self, renderer)
1707 self.patch.draw(renderer)
1708 mimage._draw_list_compositing_images(
-> 1709 renderer, self, artists, self.suppressComposite)
1710
1711 renderer.close_group('figure')
~\Anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
133 if not_composite or not has_images:
134 for a in artists:
--> 135 a.draw(renderer)
136 else:
137 # Composite any adjacent images together
~\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
36 renderer.start_filter()
37
---> 38 return draw(artist, renderer, *args, **kwargs)
39 finally:
40 if artist.get_agg_filter() is not None:
~\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in draw(self, renderer, inframe)
2643 renderer.stop_rasterizing()
2644
-> 2645 mimage._draw_list_compositing_images(renderer, self, artists)
2646
2647 renderer.close_group('axes')
~\Anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
133 if not_composite or not has_images:
134 for a in artists:
--> 135 a.draw(renderer)
136 else:
137 # Composite any adjacent images together
~\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
36 renderer.start_filter()
37
---> 38 return draw(artist, renderer, *args, **kwargs)
39 finally:
40 if artist.get_agg_filter() is not None:
~\Anaconda3\lib\site-packages\matplotlib\axis.py in draw(self, renderer, *args, **kwargs)
1204 ticks_to_draw = self._update_ticks()
1205 ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
-> 1206 renderer)
1207
1208 for tick in ticks_to_draw:
~\Anaconda3\lib\site-packages\matplotlib\axis.py in _get_tick_bboxes(self, ticks, renderer)
1149 """Return lists of bboxes for ticks' label1's and label2's."""
1150 return ([tick.label1.get_window_extent(renderer)
-> 1151 for tick in ticks if tick.label1.get_visible()],
1152 [tick.label2.get_window_extent(renderer)
1153 for tick in ticks if tick.label2.get_visible()])
~\Anaconda3\lib\site-packages\matplotlib\axis.py in <listcomp>(.0)
1149 """Return lists of bboxes for ticks' label1's and label2's."""
1150 return ([tick.label1.get_window_extent(renderer)
-> 1151 for tick in ticks if tick.label1.get_visible()],
1152 [tick.label2.get_window_extent(renderer)
1153 for tick in ticks if tick.label2.get_visible()])
~\Anaconda3\lib\site-packages\matplotlib\text.py in get_window_extent(self, renderer, dpi)
888 raise RuntimeError('Cannot get window extent w/o renderer')
889
--> 890 bbox, info, descent = self._get_layout(self._renderer)
891 x, y = self.get_unitless_position()
892 x, y = self.get_transform().transform_point((x, y))
~\Anaconda3\lib\site-packages\matplotlib\text.py in _get_layout(self, renderer)
289 _, lp_h, lp_d = renderer.get_text_width_height_descent(
290 "lp", self._fontproperties,
--> 291 ismath="TeX" if self.get_usetex() else False)
292 min_dy = (lp_h - lp_d) * self._linespacing
293
~\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in get_text_width_height_descent(self, s, prop, ismath)
199 fontsize = prop.get_size_in_points()
200 w, h, d = texmanager.get_text_width_height_descent(
--> 201 s, fontsize, renderer=self)
202 return w, h, d
203
~\Anaconda3\lib\site-packages\matplotlib\texmanager.py in get_text_width_height_descent(self, tex, fontsize, renderer)
446 else:
447 # use dviread. It sometimes returns a wrong descent.
--> 448 dvifile = self.make_dvi(tex, fontsize)
449 with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:
450 page, = dvi
~\Anaconda3\lib\site-packages\matplotlib\texmanager.py in make_dvi(self, tex, fontsize)
336 self._run_checked_subprocess(
337 ["latex", "-interaction=nonstopmode", "--halt-on-error",
--> 338 texfile], tex)
339 for fname in glob.glob(basefile + '*'):
340 if not fname.endswith(('dvi', 'tex')):
~\Anaconda3\lib\site-packages\matplotlib\texmanager.py in _run_checked_subprocess(self, command, tex)
306 raise RuntimeError(
307 'Failed to process string with tex because {} could not be '
--> 308 'found'.format(command[0])) from exc
309 except subprocess.CalledProcessError as exc:
310 raise RuntimeError(
RuntimeError: Failed to process string with tex because latex could not be found
<Figure size 432x288 with 1 Axes>