python matploitlib 学习笔记(一)

本文详细介绍了matplotlib.pyplot的基本使用方法,包括如何通过plot()函数生成图形,以及如何使用axis()函数设置坐标轴范围。此外,还展示了如何通过plot()函数的第三个字符串参数调整图形的样式,并通过setp()函数调整图形属性的显示。文章还演示了如何创建子图以及如何清除当前图形和轴。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.matplotlib.pyplot生成一个图形。而pyplot下的各个函数则改变这个图形。

例如:

import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.ylabel(’some numbers’)
plt.show()
plot()函数当参数为一个列表或数组时候,则参数生成的是y轴的数据,x轴的默认为从0开始的整数。

plot()函数当两个参数为两个列表或数组时,输入的参数依次为x.y轴的数据。
plot()函数还可以有第三个字符串参数,字符串第一个表示做的点的颜色,第二个是做的点的类型,如‘-’表示直线,‘*’表示点为*形。

axis()函数可以输入参数:[xmin, xmax, ymin, ymax]依次表示xy轴最大最小。

2.In fact, all sequences are converted to numpy arrays internally.(所有输入到plot的序列最后都在内部转变成numpy数组)

plot还能这么用:plt.plot(t, t, ’r--’, t, t**2, ’bs’, t, t**3, ’g^’)

3.还能这样设置图形:
lines = plt.plot(x1, y1, x2, y2)
# use keyword args
plt.setp(lines, color=’r’, linewidth=2.0)
# or MATLAB style string value pairs
plt.setp(lines, ’color’, ’r’, ’linewidth’, 2.0)
Property                        Value Type
alpha                             float
animated                       [True | False]
antialiased or aa           [True | False]
clip_box                         a matplotlib.trans

可以调用:

 lines = plt.plot([1,2,3])
 plt.setp(lines)

来实现课调整属性的显示。

4.

import matplotlib.pyplot as plt
plt.figure(1) # the first figure
plt.subplot(211) # the first subplot in the first figure
plt.plot([1,2,3])
plt.subplot(212) # the second subplot in the first figure
plt.plot([4,5,6])

其中,figure(1)表示figure表示做的是图一。

plt.subplot(211)表示做的两行一列的图。下面做的是第一个图。

You can clear the current figure with clf() and the current axes with cla(). If you find this statefulness,
annoying, don’t despair, this is just a thin stateful wrapper around an object oriented API, which you can
use instead (see Artist tutorial)

 

 

 
 

转载于:https://www.cnblogs.com/lisongfeng9213/p/3572394.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值