0%

Python数据图模板

By Z.H. Fu
https://fuzihaofzh.github.io/blog/

用Python处理数据,用matplotlib来做数据显示,比matlab美观的多,而且图标上能直接插入LaTeX\LaTeX。因而,采用matplotlib来显示数据是一种非常好的方式,但是,他的可配置的东西比较多,每次查起来都比较麻烦,故而编写了一个模板。其中中文的使用,参见《matplotlib中文加载方式》。效果及代码如下:

效果:

matplotlibtemplate.png

python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
   #-*- coding: utf-8 -*-
import numpy.matlib
import matplotlib.pyplot as plt
from pylab import *

def DrawData(xdata,ydata,style,tlabel):
plt.plot(xdata,ydata,style,label = tlabel)
plt.plot(xdata,ydata)

#=======User Data
xpanelNum =[20524,46678,70734,85420,94588,161162,171896,190154,237754,269948,381950,478990,561684,631228,769506,825830,1087336,1409970,1721682,1922332,2158232]
ySerial = [0,0,16,15,16,16,15,16,31,31,47,62,62,78,109,109,140,187,234,250,281]
yParallel = [0,0,0,0,0,0,0,0,0,0,15,15,15,31,31,32,47,62,78,78,94]
DrawData(xpanelNum,ySerial,'*',u"串行")
DrawData(xpanelNum,yParallel,'o',u"并行")


#======Whole Figure
plt.title(u"结果比较",fontsize=16)
plt.ylabel(u"时间/ms",fontsize=16)
plt.xlabel(u"面元个数",fontsize=16)
plt.ticklabel_format(style='sci',axis='x',scilimits=(0,0))
plt.legend(fancybox = True,loc=0)
plt.grid(linestyle="-")
plt.show()