首页 > 编程语言 > 详细

python-matplotlib

时间:2017-06-05 18:16:54      阅读:335      评论:0      收藏:0      [点我收藏+]

直奔主题吧。。以下是对matplotlib画图的简单讲解,代码已测试。

win7 + pycharm + python 2.7

参考文档:

http://old.sebug.net/paper/books/scipydoc/matplotlib_intro.html


 

捷径:查看gallery,寻找要画的图,copy代码,修改,done

http://matplotlib.org/gallery.html

技术分享

# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 10, 1000)
y = np.sin(x)
z = np.cos(x**2)

# figsize:单位为英寸 dpi:指定绘图对象的分辨率,default is 80.
# 宽度现在为8*80=640
# 但是用工具栏中的保存按钮保存下来的png图像的大小是800*400像素。

plt.figure(figsize=(8,4))
# latex inserted, use it directly.
plt.plot(x,y,label="$sin(x)$",color="red",linewidth=2)
# "b--":formated string, blue and dashed line
plt.plot(x,z,"b--",label="$cos(x^2)$")
plt.xlabel("Time(s)")
plt.ylabel("Volt")
plt.title("PyPlot First Example")
plt.ylim(-2, 2)
plt.legend()
plt.show()

# figure(i) means draw ith figure. If i exists, it will not create new figure object,
# but make it as current figure object

plt.figure(1)
plt.plot(x,y,label="$sin(x)$",color="red",linewidth=2)
plt.show()
plt.figure(2)
plt.plot(x,z,"b--",label="$cos(x^2)$")
plt.show()

  

python-matplotlib

原文:http://www.cnblogs.com/pxy7896/p/6946378.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!