<legend id='hen1k'><style id='hen1k'><dir id='hen1k'><q id='hen1k'></q></dir></style></legend>

  1. <i id='hen1k'><tr id='hen1k'><dt id='hen1k'><q id='hen1k'><span id='hen1k'><b id='hen1k'><form id='hen1k'><ins id='hen1k'></ins><ul id='hen1k'></ul><sub id='hen1k'></sub></form><legend id='hen1k'></legend><bdo id='hen1k'><pre id='hen1k'><center id='hen1k'></center></pre></bdo></b><th id='hen1k'></th></span></q></dt></tr></i><div id='hen1k'><tfoot id='hen1k'></tfoot><dl id='hen1k'><fieldset id='hen1k'></fieldset></dl></div>
    <tfoot id='hen1k'></tfoot>

      <small id='hen1k'></small><noframes id='hen1k'>

        <bdo id='hen1k'></bdo><ul id='hen1k'></ul>
    1. 如何让 matplotlib 和 Latex 一起工作?

      How to get matplotlib and latex work together?(如何让 matplotlib 和 Latex 一起工作?)
      <i id='P2F3O'><tr id='P2F3O'><dt id='P2F3O'><q id='P2F3O'><span id='P2F3O'><b id='P2F3O'><form id='P2F3O'><ins id='P2F3O'></ins><ul id='P2F3O'></ul><sub id='P2F3O'></sub></form><legend id='P2F3O'></legend><bdo id='P2F3O'><pre id='P2F3O'><center id='P2F3O'></center></pre></bdo></b><th id='P2F3O'></th></span></q></dt></tr></i><div id='P2F3O'><tfoot id='P2F3O'></tfoot><dl id='P2F3O'><fieldset id='P2F3O'></fieldset></dl></div>
    2. <legend id='P2F3O'><style id='P2F3O'><dir id='P2F3O'><q id='P2F3O'></q></dir></style></legend>
        <tbody id='P2F3O'></tbody>

        1. <tfoot id='P2F3O'></tfoot>

              <bdo id='P2F3O'></bdo><ul id='P2F3O'></ul>

                <small id='P2F3O'></small><noframes id='P2F3O'>

                本文介绍了如何让 matplotlib 和 Latex 一起工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有以下问题,我对 matplotlib 和 python 完全陌生:为了为我的论文生成高质量的图,我想使用 matplotlib,我想对轴等使用乳胶命令.当我尝试以下示例时(来自 http://matplotlib.org/users/usetex.html#usetex-tutorial):

                I have the following problem and I am totally new to matplotlib and python: To produce high qualitiy plots for my thesis I want to use matplotlib and I want to use the latex commands for the axes etc. When I try the following example (from http://matplotlib.org/users/usetex.html#usetex-tutorial):

                import numpy as np 
                import matplotlib.pyplot as plt
                
                
                # Example data 
                t = np.arange(0.0, 1.0 + 0.01, 0.01) 
                s = np.cos(4 * np.pi * t) + 2
                
                plt.rc('text', usetex=True) 
                plt.rc('font', family='serif') 
                plt.plot(t, s)
                
                plt.xlabel(r'	extbf{time} (s)')
                plt.ylabel(r'	extit{voltage} (mV)',fontsize=16) 
                plt.title(r"TeX is Number "
                          r"$displaystylesum_{n=1}^inftyfrac{-e^{ipi}}{2^n}$!",
                          fontsize=16, color='gray')
                # Make room for the ridiculously large title. 
                plt.subplots_adjust(top=0.8)
                
                plt.savefig('tex_demo') 
                plt.show()
                

                我收到以下消息:

                  File "test.py", line 21, in <module>
                    plt.savefig('tex_demo')
                  File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 561, in savefig
                    return fig.savefig(*args, **kwargs)
                  File "/usr/lib/pymodules/python2.7/matplotlib/figure.py", line 1421, in savefig
                    self.canvas.print_figure(*args, **kwargs)
                  File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 2220, in print_figure
                    **kwargs)
                  File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_agg.py", line 505, in print_png
                    FigureCanvasAgg.draw(self)
                  File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_agg.py", line 451, in draw
                    self.figure.draw(self.renderer)
                  File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
                    draw(artist, renderer, *args, **kwargs)
                  File "/usr/lib/pymodules/python2.7/matplotlib/figure.py", line 1034, in draw
                    func(*args)
                  File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
                    draw(artist, renderer, *args, **kwargs)
                  File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 2086, in draw
                    a.draw(renderer)
                  File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
                    draw(artist, renderer, *args, **kwargs)
                  File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 1105, in draw
                    self.label.draw(renderer)
                  File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
                    draw(artist, renderer, *args, **kwargs)
                  File "/usr/lib/pymodules/python2.7/matplotlib/text.py", line 594, in draw
                    self._fontproperties, angle, mtext=self)
                  File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_agg.py", line 241, in draw_tex
                    self._renderer.draw_text_image(Z, x, y, angle, gc)
                OverflowError: cannot convert float infinity to integer
                

                我是 Linux (Ubuntu 14.04) 的新手,安装 matplotlib 时可能做错了什么;这是我为安装 matplotlib 等所做的:

                I'm new to Linux (Ubuntu 14.04) and maybe have done something wrong when installing matplotlib; here is what I have done to install matplotlib etc.:

                sudo apt-get install python3
                sudo apt-get install python-matplotlib
                sudo apt-get build-dep python-matplotlib
                

                我正在使用 texmaker 并认为这可能是问题所在;所以我做了以下事情:

                I am using texmaker and thought this could be the problem; so I did the following:

                sudo aptitude install texlive-fonts-recommended texlive-fonts-extra
                

                如果我尝试任何其他绘图,包括乳胶命令,我会收到类似的错误消息,或者绘图没有任何轴标签.

                If I try any other plots including latex commands I get similar error messages, or plots without any lables for the axes.

                推荐答案

                您的问题之前已被视为 在 matplotlib-user 邮件列表中报告.决议 在这里 并确认它的工作原理在这里.

                Your problem has been seen before as reported here on the matplotlib-user mailing list. The resolution is here and the confirmation that it works is here.

                综上,需要清除tex.cache目录.

                In summary, you need to clear the tex.cache directory.

                要查找该目录的位置 - 进入 python 并执行 matplotlib.get_cachedir()

                To find where that directory is - go into python and execute matplotlib.get_cachedir()

                对于标准的 Ubuntu 14.04 安装 - 您应该得到如下内容:

                For a standard Ubuntu 14.04 install - you should get something like the following:

                ~$ python3
                Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
                [GCC 4.8.2] on linux
                Type "help", "copyright", "credits" or "license" for more information.
                >>> import matplotlib as mpl
                >>> mpl.get_cachedir()
                '/home/<username>/.cache/matplotlib'
                

                然后执行 rm <path/to/cache/from/above>/tex.cache/* 然后重新运行,它应该一切正常.

                Then do rm <path/to/cache/from/above>/tex.cache/* and then re-run and it should all work.

                usetex 故障排除文档部分中提供了一些类似的技巧,该部分会导致到 这里 来定位目录,但是他们不幸的是,不要提及 get_cachedir()

                Some tips like this are available in the usetex troubleshooting docs section, which lead to here to locate the directory, but they unfortunately don't mention get_cachedir()

                编辑 拉取请求a> 基于此问题生成并合并到 matplotlib 文档中.

                Edit Pull Request generated based on this question and merged into the matplotlib docs.

                这篇关于如何让 matplotlib 和 Latex 一起工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)

                  • <bdo id='BYE6h'></bdo><ul id='BYE6h'></ul>

                    <small id='BYE6h'></small><noframes id='BYE6h'>

                        <tbody id='BYE6h'></tbody>
                    1. <tfoot id='BYE6h'></tfoot>

                        <legend id='BYE6h'><style id='BYE6h'><dir id='BYE6h'><q id='BYE6h'></q></dir></style></legend>
                        • <i id='BYE6h'><tr id='BYE6h'><dt id='BYE6h'><q id='BYE6h'><span id='BYE6h'><b id='BYE6h'><form id='BYE6h'><ins id='BYE6h'></ins><ul id='BYE6h'></ul><sub id='BYE6h'></sub></form><legend id='BYE6h'></legend><bdo id='BYE6h'><pre id='BYE6h'><center id='BYE6h'></center></pre></bdo></b><th id='BYE6h'></th></span></q></dt></tr></i><div id='BYE6h'><tfoot id='BYE6h'></tfoot><dl id='BYE6h'><fieldset id='BYE6h'></fieldset></dl></div>