Python数据分析 Ⅱ:matplotlib模块

Data Analysis in Python : matplotlib module

模块安装与引入

安装

pip install matplotlib

引用pyplot子库

import matplotlib.pyplot as plt

在高中阶段的信息技术课程要求仅为可以使用pyplot子库提供函数绘图即可,故后文也仅讲此子库函数方法及呈现。

图表

我们从小学开始就接触图表,学到了柱状图📊,到之后初中学了折线图(线形图)。如果你留意Office类办公软件的话你会发现Excel的 插入>图表 选项卡中还有一堆你不认识的图表样式。其中我们信息技术课还需要知道散点图。如下就是个很经典的散点图
scatter
散点图可以表示通过多个坐标点来描绘出出数据的大致趋势,在数学中会用于回归分析,使用合适的函数对数据点进行拟合。散点图还会衍生出来很多图表比如气泡图等等类型。
还有柱形图有水平(barh)和垂直(bar)的两种,注意这两种在模块中命名有些许区别。其实也有个巧记的方法就是 水平(barh)-横(héng)

绘图

pyplot 中最基础的作图方式是以点作图,即给出每个点的坐标,pyplot 会将这些点在坐标系中画出,并用线将这些点连起来,即绘图前需将坐标点数据准备好。
数据可以是列表、字典、pandas中Series/DataFrame对象中的数据、excel表格读入,numpy/math模块生成等等

代码

(图遗失)

这部分的代码结构都比较固定。一共可以划分6为个部分:

①引入模块 ②格式处理(一般会给注释,不做考试要求) ③源数据 ④绘制图形代码 ⑤修饰美化 ⑥显示

实例

心型线

import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['axes.unicode_minus']=False  #运行配置参数总的轴(axes)正常显示正负号(minus)
t=np.linspace(-10,10,1000)
x=16*np.sin(t)**3
y=13*np.cos(t)-5*np.cos(2*t)-2*np.cos(3*t)-np.cos(4*t)
plt.plot(x,y)
plt.show()

上文使用Markdown编写,使用Obsidian发布

评论

6 条对“Python数据分析 Ⅱ:matplotlib模块”的回复

  1. h666game 的头像

    Giving h666game a shot. It’s got a decent selection of games and the site’s not too hard to figure out. Could be a good spot to unwind after work. Take a look at h666game and enjoy!

  2. h666gameonline 的头像

    H666gameonline has some of the most addictive online games around. If you are looking for a good way to kill some time, I recommend checking h666gameonline.com out: h666gameonline!

  3. hh88casino 的头像

    Looking for a new casino site and decided to give hh88casino a try. The bonuses are pretty good, and they have a decent selection of table games. Hope my luck turns around, gonna test it this week. hh88casino seems promising!

  4. jili50 login 的头像

    Struggling to remember my Jili50 login details! Anyone else have this problem? Haha! Here’s the login page anyway: jili50 login

  5. winner.mx 的头像

    Been checking out Winner.mx lately. Seems like a pretty solid option for online gaming here in Mexico. Some cool games and decent promos. Worth a look! Get on winner.mx

  6. swerte777 的头像

    If you are looking for a fun place to play, Swerte777 is worth a shot. Plus, the site’s slick. Here’s the link: swerte777

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注