matplotlib介绍-画出优美的图形

官网:https://matplotlib.org/contents.html

matplotlib是一个Python的会图库,以各种硬拷贝格式和跨平台的交互式环境生成出版质量级别的图形,它能够输出的图形包括折线图、散点图,直方图等。在数据可视化方面,matplotlib拥有数量众多的忠实用户,其强悍的绘图能力能够帮助我们对数据形成非常清晰直观的认识,下面我们来简单展示一下matplotlib的能力。

%matplotlib inline
import numpy as np
#激活matplotlib
import matplotlib.pyplot as plt
#下面生成一个从-20到20,元素数为10的等差数列
x = np.linspace(-20,20,10)
#再令y = x^3 +2x^2 + 6x + 5
y = x**3 + 2*x**2 + 6*x + 5
#下面画出这条函数的曲线
plt.plot(x,y, marker = "o")

开头的%matplotlib inline表示jupyter Botebook进行内置实时的绘图。

否则在最后一行加入plt.show()进行显示,这样绘图才能显示出来。

还有一些比较重要的模块:

matplotlib.pyplot

Provides a MATLAB-like plotting framework.

pylab combines pyplot with numpy into a single namespace. This is convenient for interactive work, but for programming it is recommended that the namespaces be kept separate, e.g.:

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 5, 0.1);
y = np.sin(x)
plt.plot(x, y)
  • cm 模块

matplotlib.cm

Builtin colormaps, colormap handling utilities, and the ScalarMappable mixin.

matplotlib.gridspec

gridspec is a module which specifies the location of the subplot in the figure.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值