matplotlib 生成 eps,就能够插入到 tex 中,并且是矢量图,放大不失真。javascript
并且由于图中的元素都是嵌入到 pdf 中,因此图中的文字也能够选中及复制。java
注意 matplotlib 的 backend 要选择 Agg ,用 TkAgg 做为 backend 只能生成一张空白图片。python
testeps.pysegmentfault
1 import matplotlib 2 matplotlib.use('Agg') 3 import matplotlib.pyplot as plt 4 x=range(100) 5 y=[i**2 for i in x] 6 plt.plot(x,y,label='x**2') 7 plt.legend(frameon=False) 8 plt.xlabel('x') 9 plt.ylabel('y') 10 plt.title('x**2') 11 plt.savefig('testeps.eps',format='eps')
testeps.tex网络
\documentclass[12pt]{article} \usepackage{fontspec} \usepackage{graphicx} \setmainfont{SimHei} \title{x**2} \author{maxuewei} \date{} \begin{document} \maketitle \begin{center} $$ y=x^2 $$ 即 $$ y=x*x $$ 图像以下\\ \end{center} \begin{figure}[htbp] \centering\includegraphics[width=320pt]{testeps.eps} %\caption{something}\label{fig:1} \end{figure} \end{document}
用xelatex编译,生成pdf。app
1 #encoding=utf-8 2 import matplotlib 3 matplotlib.use('Agg') 4 import matplotlib.font_manager as fm 5 myfont = fm.FontProperties(fname='/usr/share/fonts/WinFonts/simhei.ttf') 6 import matplotlib.pyplot as plt 7 plt.clf() 8 x=range(100) 9 y=[i**2 for i in x] 10 plt.plot(x,y) 11 plt.legend([u'x**2图例'],prop=myfont,frameon=False) 12 plt.xlabel('x') 13 plt.ylabel('y') 14 plt.title(u'x**2的图像',fontproperties=myfont) 15 plt.savefig('testeps_pdf.pdf',format='pdf')
(参考 wesleyhsiung 在 matplotlib图例中文乱码? 下的 回答 )工具
或post
1 #encoding=utf-8 2 import matplotlib 3 matplotlib.use('Agg') 4 import matplotlib.pyplot as plt 5 plt.rcParams['font.sans-serif'] = ['SimHei'] #用来正常显示中文标签 6 plt.rcParams['axes.unicode_minus'] = False #用来正常显示负号 7 8 plt.clf() 9 x=range(100) 10 y=[i**2 for i in x] 11 plt.plot(x,y) 12 plt.legend([u'x**2图例'],frameon=False) 13 plt.xlabel('x') 14 plt.ylabel('y') 15 plt.title(u'x**2的图像') 16 plt.savefig('testeps_pdf.pdf',format='pdf')
(参考 python matplotlib 中文显示参数设置 )网站
生成pdfui
而后终端运行
pdf2ps testeps_pdf.pdf testeps.eps
将 pdf 转成 eps
而后就能够像上面同样编译tex了。
不过最终生成的pdf,图像部分的文字没法选中,没法像上面同样能够选中及复制。
使用 MS PowerPoint、WPS、Libre office、xfig、Dia、yEd、Inkscape、LatexDraw、Ipe、TikzEdt 等画图并导出 eps 或 pdf ,而后插入到 tex 。
方法以下:
使用 WPS 或 Libreoffice Draw 或 Libreoffice Impress 画好图以后,导出 pdf,而后使用 pdfcrop 或相似工具对pdf进行裁剪
pdfcrop --margins "5 5 5 5" ppt.pdf final.pdf
使用 yED 时要注意在 Text Rendering Policy 中选择 Vectorized Text 以外的选项。
另外一种不错的方法是使用 Dia 画图,而后导出 pgf 的 tex 代码,假如导出为 dia_export.tex,在主文档中 \include{dia_export} 就能够了。
由于在 Dia 中不支持数学公式,因此能够在用 Dia 画图时先敲入公式,再在导出的 dia_export.tex 中把它对 $ \ 等的转义去掉,再用 LaTex 编译就能够了。
若是须要在背景颜色不为白色的 PDF 中插入图的话,画图时能够在『文件-图表属性』下设置背景颜色为灰色,而后对于图中的元素『右键-属性』,设置『填充颜色』、『线条颜色』等,其中有一个『透明度』的选项能够设置为 0 即为透明。
使用 graphviz/dot 语言画图,可方便地画出树、流程图等。
使用 D3.js、Chart.js 等 JavaScript 库画图。见 Javascript chart library。
使用 TikZ、Metapost 等。
使用 draw.io、gliffy、lucidchart、processon 等在线网站。
使用 gephi 等绘制网络。
What GUI applications are there to assist in generating graphics for TeX?
Which open source software is best for network data analysis?
2017.08.21 19:35