各位用户为了找寻关于python绘图方法实例入门的资料费劲了很多周折。这里教程网为您整理了关于python绘图方法实例入门的相关资料,仅供查阅,以下为您介绍关于python绘图方法实例入门的详细内容
本文实例讲述了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 27 28 29 30 31 32 33 34 35 36# -*- coding:utf-8 -*-
import
matplotlib.pyplot as plt
def
main():
# 颜色列表
colorList
=
[
'b'
,
'g'
,
'r'
,
'c'
,
'm'
,
'y'
,
'k'
]
# 共用的横坐标
threadList
=
[
1
,
2
,
4
,
8
,
10
]
# 设置横坐标和纵坐标的名称
plt.xlabel(
'threads'
)
plt.ylabel(
'concurrent'
)
# 图的标题
plt.title(
'concurrent test'
)
# 要绘制的线的列表
lines
=
[]
# 对应的线的名称
titles
=
[]
# 第一根线的纵坐标
dataList1
=
[
2
,
5
,
7
,
15
,
30
]
# 根据横坐标和纵坐标画第一根线
line1
=
plt.plot(threadList, dataList1)
# 设置线的颜色宽度等
plt.setp(line1, color
=
colorList[
0
], linewidth
=
2.0
)
# 线的名称
titles.append(
'Linux'
)
lines.append(line1)
# 同理画第二根线
dataList2
=
[
2
,
4
,
6
,
18
,
35
]
line2
=
plt.plot(threadList, dataList2)
plt.setp(line2, color
=
colorList[
1
], linewidth
=
2.0
)
titles.append(
'FreeBSD'
)
lines.append(line2)
plt.legend(lines, titles)
plt.savefig(
'/home/workspace/test.png'
, dpi
=
120
)
#如果是pdf就,plt.savefig('/home/workspace/test.pdf')
if
__name__
=
=
'__main__'
:
main()
希望本文所述对大家的Python程序设计有所帮助。