Matplotlib drawing a picture that meets the requirements of the paper

Source: Internet
Author: User
The experimental data needs to be drawn out recently, and as a result of experiments using Python, matplotlib is naturally used to draw.

The following code can be used as the template code for the drawing, with detailed comments in the code that can be changed as needed.

  

 1 #-*-Coding:utf-8-*-2 import numpy as NP 3 import Matplotlib.pyplot as Plt 4 plt.rcparams[' Font.sans-serif ']=[' Aria L '] #如果要显示中文字体, set here: Simhei 5 plt.rcparams[' Axes.unicode_minus ']=false #显示负号 6 7 x = Np.array ([3,5,7,9,11,13,15,17,  19,21]) 8 A = Np.array ([0.9708, 0.6429, 1, 0.8333, 0.8841, 0.5867, 0.9352, 0.8000, 0.9359, 0.9405]) 9 b= np.array ([0.9708,  0.6558, 1, 0.8095, 0.8913, 0.5950, 0.9352, 0.8000, 0.9359, 0.9419]) C=np.array ([0.9657, 0.6688, 0.9855, 0.7881, 0.8667, 0.5952, 0.9361, 0.7848, 0.9244, 0.9221]) D=np.array ([0.9664, 0.6701, 0.9884, 0.7929, 0.8790, 0.6072, 0.9352, 0.7920, 0. 9170, 0.9254]) is shown in #label在图示 (legend).    For a mathematical formula, it is best to add the "$" symbol before and after the string #color: B:blue, G:green, r:red, C:cyan, M:magenta, Y:yellow, K:black, W:white 、、、 #线型:----.    :, #marker:.            , O v < * + 117 plt.figure (figsize= (10,5)) Plt.grid (LineStyle = "--") #设置背景网格线为虚线19 ax = PLT.GCA () ax.spines[' top '].set_visible (False) #去掉上边框21 ax.spines[' right '].set_visible (False) #去掉右边框22 plt.plot (x,a,color= "Black", label= "A algorithm", linewidth=1.5) 24 Plt.plot (X,b, "k--", label= "B algorithm", linewidth=1.5) Plt.plot (x,c,color= "Red", label= "C algorithm", linewidth= 1.5) Plt.plot (x,d, "r--", label= "D algorithm", linewidth=1.5) group_labels=[' DataSet1 ', ' Dataset2 ', ' dataset3 ', ' Dataset4 ', ' dataset5 ', ' dataset6 ', ' dataset7 ', ' dataset8 ', ' dataset9 ', ' dataset10 '] #x轴刻度的标识29 plt.xticks (x,group_ Labels,fontsize=12,fontweight= ' bold ') #默认字体大小为1030 plt.yticks (fontsize=12,fontweight= ' bold ') to Plt.title ("example ", fontsize=12,fontweight= ' bold ') #默认字体大小为1232 Plt.xlabel (" Data sets ", fontsize=13,fontweight= ' bold ') Plt.ylabel ("                   Accuracy ", fontsize=13,fontweight= ' bold ') Plt.xlim (3,21) #设置x轴的范围35 #plt. Ylim (0.5,1) #plt. Legend () #显示各曲线的图例38 plt.legend (loc=0, numpoints=1) leg = PLT.GCA (). Get_legend () Ltext = leg.get_texts () p LT.SETP (Ltext, fontsize=12,fontweight= ' bold ') #设置图例字体的大小和粗细42 plt.saVefig (' d:\\filename.svg ', format= ' svg ') #建议保存为svg格式, then use Inkscape to convert to vector diagram emf after inserting word plt.show () 

Here is a legend for the above code drawing:

It is recommended to save the image in SVG format (because matplotlib is a problem when saved as an EPS vector), and then use the Inkscape software to convert the SVG format to the EMF vector image format. If there are many SVG pictures, you can use batch processing under Windows (remember to set the path path after installing the Inkscape software), the following code can convert the SVG file in its directory into an EMF file. Copy the following code to a text file with the suffix named bat.

  

1 @echo off2 for%%i in (*.svg) do (3     echo%%i4     inkscape-f%%i-m%%~ni.emf5) 6 @echo finished
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.