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. Linux命令(十一)——Shell程序设计二(循环控制语句)

    1.if语句 (1)两路分支的if语句 (2)多路条件判断分支的if语句 2.测试语句 (1)文件测试 (2)字符串测试 (3)数值测试 (4)用逻辑操作符进行组合的测试语句 3.case语句 4.f ...

  2. JS垃圾回收——和其他语言一样,JavaScript 的 GC 策略也无法避免一个问题:GC 时,停止响应其他操作,这是为了安全考虑

    JavaScript 内存管理 & 垃圾回收机制 标记清除 js 中最常用的垃圾回收方式就是标记清除.当变量进入环境时,例如,在函数中声明一个变量,就将这个而变量标记为“进入环境”.从逻辑上讲 ...

  3. Gym-100935I Farm 计算几何 圆和矩形面积交

    题面 题意:就是给你一个圆,和你一个矩形,求面积并,且 保证是一种情况:三角剖分后 一个点在圆内 两个在圆外 题解:可以直接上圆与凸多边形交的板子,也可以由这题实际情况,面积等于扇形减两个三角形 #i ...

  4. FluentScheduler定时器

    项目需要一个按时执行的任务,每隔几分钟执行一个,或者每隔几小时执行一次等等,这个时候就需要一个定时的功能,最简单的就是用Timer自己写一个,但是自己写的性能等各方面有可能不健全等等,而现在开源的库也 ...

  5. 29. Divide Two Integers[M]两数相除

    题目 Given two integers dividend and divisor, divide two integers without using multiplication, divisi ...

  6. OCC 矩阵变换

    在OpenCADCADE中, 通过gp_Trsf类来进行矩阵变换操作, 采用矩阵在左的方式: 新点 = 变换矩阵 * 点 基本原理如下: //! Defines a non-persistent tr ...

  7. window下安装svn

    下载 http://subversion.apache.org/ 注意:上边的黑窗口不要关闭! 如何校验svn服务有运行

  8. mysql连接出现error node【1045】

    第一步:在my.ini下找到mysqlid.在后边添加skip-grant-tables 第二步:重新启动mysql服务 第三步:重新设置密码 第四步: 将skip-grant-tables删除掉,保 ...

  9. jQuery基本选择器模块(二)

    选择器模块 1.push方法的兼容性(了解) 问题:IE8不支持aplly方法中的第二个参数是 伪数组 目标:实现 push 方法的浏览器兼容性问题 var push = [].push; try { ...

  10. hdu2853 Assignment 完美匹配 多校联赛的好题

    PS:好题.不看题解绝对AC不了. 题解来源: http://blog.csdn.net/niushuai666/article/details/7176290 http://www.cnblogs. ...