参考:http://matplotlib.org/api/pyplot_api.html
画图功能总结(2):http://blog.youkuaiyun.com/mmc2015/article/details/48222611
1、matplotlib.pyplot.plot(*args, **kwargs),最简单的沿坐标轴划线函数:
下面四种格式都合法:
plot(x, y) # plot x and y using default line style and color plot(x, y, 'bo') # plot x and y using blue circle markers plot(y) # plot y using x as index array 0..N-1 plot(y, 'r+') # ditto, but with red plusses
<pre name="code" class="python">import numpy as np
import matplotlib.pyplot as plt
x1=np.arange(0,5,0.1)
y1=np.sin(x1)
x2=np.linspace(1,10,20,True)
y2=np.cos(x2)
plt.plot(x1,y1,'b^')
plt.plot(x1, y1, 'go', x2, y2, 'r-')
如果颜色不显示指出,则默认循环使用不同的颜色,支持的颜色有:
| character | color |
|---|---|
| ‘b’ | blue |
| ‘g’ | green |
| ‘r’ | red |
| ‘c’ | cyan |
| ‘m’ | magenta |
| ‘y’ | yellow |
| ‘k’ | black |
| ‘w’ | white |
| character | description |
|---|---|
| '-' | solid line style |
| '--' | dashed line style |
| '-.' | dash-dot line style |
| ':' | dotted line style |
| '.' | point marker |
| ',' | pixel marker |
| 'o' | circle marker |
| 'v' | triangle_down marker |
| '^' | triangle_up marker |
| '<' | triangle_left marker |
| '>' | triangle_right marker |
| '1' | tri_down marker |
| '2' | tri_up marker |

本文总结了matplotlib.pyplot的基本画图功能,包括plot函数的使用,如指定颜色、坐标范围、添加轴标签和标题、绘制网格。此外,还介绍了scatter函数用于创建散点图,强调了它与plot的不同之处,如不能同时画多条曲线,并给出了实例展示。最后提到了hold关键字在连续绘制图形时的作用。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



