Python - Datacamp - Introduction to Matplotlib

Datacamp: https://www.datacamp.com/

# 1.py 基本matplotlib.pyplot子模块入门

# Import the matplotlib.pyplot submodule and name it plt
import matplotlib.pyplot as plt # Create a Figure and an Axes with plt.subplots
fig, ax = plt.subplots() # Call the show function
plt.show()
# 2.py 添加数据

import matplotlib.pyplot as plt

# 月份
MONTH = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
# 降雨量
rainfall = [44.10, 71.08, 93.36, 184.63, 286.79, 318.60, 238.22, 233.75, 194.35, 68.65, 38.40, 29.32] # 数据
data = {}
data['MONTH'] = MONTH
data['rainfall'] = rainfall # 创建数据以及轴
fig, ax = plt.subplots() # ax: (x, y)
ax.plot(data['MONTH'], data['rainfall']) # 显示
plt.show()
# 3.py 自定义显示

import matplotlib.pyplot as plt

# 月份
MONTH = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
# 降雨量
rainfall = [44.10, 71.08, 93.36, 184.63, 286.79, 318.60, 238.22, 233.75, 194.35, 68.65, 38.40, 29.32] # 数据
data = {}
data['MONTH'] = MONTH
data['rainfall'] = rainfall # 创建数据以及轴
fig, ax = plt.subplots() # ax: (x, y)
ax.plot(data['MONTH'], data['rainfall'], color='b', marker='*', linestyle='--') # 显示
plt.show()
# 4.py 自定义标签以及抬头

import matplotlib.pyplot as plt

# 月份
MONTH = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
# 降雨量
rainfall = [44.10, 71.08, 93.36, 184.63, 286.79, 318.60, 238.22, 233.75, 194.35, 68.65, 38.40, 29.32] # 数据
data = {}
data['MONTH'] = MONTH
data['rainfall'] = rainfall # 创建数据以及轴
fig, ax = plt.subplots() # ax: (x, y)
ax.plot(data['MONTH'], data['rainfall'], color='b', marker='*', linestyle='--') # 标签
ax.set_xlabel('Months')
ax.set_ylabel('Rainfall in CAN') # 标题
ax.set_title('Weather in CAN') # 显示
plt.show()
# 5.py 多重图表

import matplotlib.pyplot as plt

# 月份
MONTH_F = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
MONTH_L = ['Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
# 降雨量
rainfall_canton_F = [44.10, 71.08, 93.36, 184.63, 286.79, 318.60]
rainfall_shanghai_F = [61.79, 59.40, 94.99, 83.19, 92.78, 173.57]
rainfall_canton_L = [238.22, 233.75, 194.35, 68.65, 38.40, 29.32]
rainfall_shanghai_L = [148.84, 193.88, 109.60, 62.44, 54.14, 37.71] # 创建数据以及轴
fig, ax = plt.subplots(2, 2) # ax: (x, y)
ax[0,0].plot(MONTH_F, rainfall_canton_F, color='b', marker='*', linestyle='--')
ax[0,1].plot(MONTH_F, rainfall_shanghai_F, color='r', marker='o', linestyle='--')
ax[1,0].plot(MONTH_L, rainfall_canton_L, color='b', marker='*', linestyle='--')
ax[1,1].plot(MONTH_L, rainfall_shanghai_L, color='r', marker='o', linestyle='--') # 标签
ax[0,0].set_xlabel('Months')
ax[0,0].set_ylabel('Rainfall in Canton')
ax[0,1].set_xlabel('Months')
ax[0,1].set_ylabel('Rainfall in Shanghai') # 标题
ax[0,0].set_title('Weather in Canton')
ax[0,1].set_title('Weather in Shanghai')
# 显示
plt.show()
# 6.py small multiples with shared y axis

import matplotlib.pyplot as plt

# 月份
MONTH = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
# 降雨量
rainfall = [44.10, 71.08, 93.36, 184.63, 286.79, 318.60, 238.22, 233.75, 194.35, 68.65, 38.40, 29.32]
# 温度
temperature = [10, 14, 20, 22, 19, 25, 30, 31, 32, 29, 15, 16] # 数据
data = {}
data['MONTH'] = MONTH
data['rainfall'] = rainfall
data['temperature'] = temperature # Create a figure and an array of axes: 2 rows, 1 column with shared y axis
fig, axes = plt.subplots(2, 1, sharey=True) axes[0].plot(data['MONTH'], data['rainfall'], color='b')
axes[0].plot(data['MONTH'], data['temperature'], color='b', linestyle='--') axes[1].plot(data['MONTH'], data['rainfall'], color='b')
axes[1].plot(data['MONTH'], data['temperature'], color='b', linestyle='--') plt.show()

Python - Datacamp - Introduction to Matplotlib的更多相关文章

  1. 学习笔记之Introduction to Data Visualization with Python | DataCamp

    Introduction to Data Visualization with Python | DataCamp https://www.datacamp.com/courses/introduct ...

  2. 在python中使用图形库matplotlib

    matplotlib is a python 2D plotting library which produces publication quality figures in a variety o ...

  3. [置顶] 如何在Windows 7 64位安装Python,并使用Matplotlib绘图

    1.     安装Python 我使用的是Windows 7 64 bit,所以我从Python官网下载python-2.7.5.amd64.msi,安装步骤如下: 1)        安装windo ...

  4. Python数据可视化——使用Matplotlib创建散点图

    Python数据可视化——使用Matplotlib创建散点图 2017-12-27 作者:淡水化合物 Matplotlib简述: Matplotlib是一个用于创建出高质量图表的桌面绘图包(主要是2D ...

  5. 【python笔记】使用matplotlib,pylab进行python绘图

    一提到python绘图,matplotlib是不得不提的python最著名的绘图库,它里面包含了类似matlab的一整套绘图的API.因此,作为想要学习python绘图的童鞋们就得在自己的python ...

  6. Python的可视化包 – Matplotlib 2D图表(点图和线图,.柱状或饼状类型的图),3D图表(曲面图,散点图和柱状图)

    Python的可视化包 – Matplotlib Matplotlib是Python中最常用的可视化工具之一,可以非常方便地创建海量类型地2D图表和一些基本的3D图表.Matplotlib最早是为了可 ...

  7. python安装matplotlib:python -m pip install matplotlib报错

    matplotlib是python中强大的画图模块. 首先确保已经安装python,然后用pip来安装matplotlib模块. 进入到cmd窗口下,建议执行python -m pip install ...

  8. Python使用pip安装matplotlib模块

    matplotlib是python中强大的画图模块. 首先确保已经安装python,然后用pip来安装matplotlib模块. 进入到cmd窗口下,建议执行python -m pip install ...

  9. 用Python的Pandas和Matplotlib绘制股票KDJ指标线

    我最近出了一本书,<基于股票大数据分析的Python入门实战 视频教学版>,京东链接:https://item.jd.com/69241653952.html,在其中给出了MACD,KDJ ...

随机推荐

  1. TagCloud with xml

    Django后台开发 加了个3D标签云的插件 3DTagCloudwithXML 中使用的是xml生成方式 为了xml自己主动化生成 而不须要去手工改动xml 特地写了个xmlgenerator 比較 ...

  2. 18005 It is not ugly number

    18005 It is not ugly number 时间限制:2000MS  内存限制:65535K提交次数:0 通过次数:0 题型: 编程题   语言: G++;GCC Description ...

  3. C# List数据批量更新

    针对单条数据一般都是update语句直接更新 例如:update UserTable set UserName='小名'   where userid=xxx 但是如果是针对List数据组进行更新的话 ...

  4. iOS 加入粘贴板的功能(复制功能)

    1.   UIPasteboard *board = [UIPasteboard generalPasteboard]; board.string = @" 须要粘贴的问题字符串" ...

  5. SharePoint创建一个简单的Visio Web部件图

    SharePoint创建一个简单的Visio Web部件图 Visio有很多强大的Mash-up混聚功能,使它能够轻松集成到SharePoint 2010中. 1. 打开Visio 2010,创建新的 ...

  6. luogu1226 取余运算||快速幂

    题目大意:快速求$a^b\mod p$的值. 根据二进制,令$b=\sum t_k\cdot 2^k, t\in \{0,1\}$,那么$$a^b=a^{\sum t_k\cdot 2^k}\mod ...

  7. nyoj--491--幸运三角形(dfs)

    幸运三角形 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 话说有这么一个图形,只有两种符号组成('+'或者'-'),图形的最上层有n个符号,往下个数依次减一,形成倒置的 ...

  8. C++_class_powerpoint_1.1

    Types and Declarations Boolean Type bool type – boolean , logic type bool literal – true, falseint a ...

  9. 2014/09/20 关于ArrayList的几种操作

    1.删除ArrayList集合元素 删除ArrayList集合里面的元素时,提供了Clear方法,Remove方法,RmoveAt方法和RemoveRange方法. Clear方法是移除所有的元素 R ...

  10. Linux&nbsp;Oracle服务启动&amp;停止脚本与开机自启动

    在CentOS 6.3下安装完Oracle 10g R2,重开机之后,你会发现Oracle没有自行启动,这是正常的,因为在Linux下安装Oracle的确不会自行启动,必须要自行设定相关参数,首先先介 ...