Python Matplotlib 学习入门(一)

初次体验:

import matplotlib.pyplot as plt
import numpy as np
# 从[-1,1]中等距去50个数作为x的取值
x = np.linspace(-2, 2, 50)
y = 2*x + 1
# 第一个是横坐标的值,第二个是纵坐标的值 plt.plot(x, y)
# 必要方法,用于将设置好的figure对象显示出来 plt.show()

 

import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-2, 2, 50) 
y = 2**x + 1 
# 第一个是横坐标的值,第二个是纵坐标的值 
plt.plot(x, y) 
plt.show()

显示多个图像:

import matplotlib.pyplot as plt 
import numpy as np 
# 多个figure x = np.linspace(-1, 1, 50) 
y1 = 2*x + 1 
y2 = 2**x + 1 
# 使用figure()函数重新申请一个figure对象 
# 注意,每次调用figure的时候都会重新申请一个figure对象 
plt.figure() 
# 第一个是横坐标的值,第二个是纵坐标的值 
plt.plot(x, y1) 
# 第一个参数表示的是编号,第二个表示的是图表的长宽 
plt.figure(num = 3, figsize=(8, 5)) 
# 当我们需要在画板中绘制两条线的时候,可以使用下面的方法: 
plt.plot(x, y2) 
plt.plot(x, y1, color='red', 
         # 线颜色 
         linewidth=1.0, 
         # 线宽 
         linestyle='--' 
         # 线样式 
        ) 
         
plt.show()

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值