Python3绘图之Matplotlib(01)

1 First plots with Matplotlib

简单的绘图1

简单的绘图2

简单的绘图3

2 网格 = grid

3 设置坐标轴的取值范围 = axis xlim ylim

方法1:整体设置

[xmin, xmax, ymin, ymax]   ===》plt.axis([xmin, xmax, ymin, ymax])

方法2:分别设置

plt.xlim([xmin, xmax])

plt.ylim([ymin, ymax])

4 设置坐标含义标签 = label

5 设置图片的整体标题 = title

6 设置图例 = legend

方法2:

plt.plot(x, x*1.5)

plt.plot(x, x*3.0)

plt.plot(x, x/3.0)

plt.legend([‘Normal‘, ‘Fast‘, ‘Slow‘])

图例的位置参数:loc = Code

String Code
best 0
upper right 1
upper left 2
lower left 3
lower right 4
right 5
center left 6
center right 7
lower center 8
upper center 9
center 10

7 一副完整的图像

8 保存图片 = savefig

import matplotlib.pyplot as plt
plt.plot([1, 2, 3])
plt.savefig("plot123.png")
plt.savefig(‘plot123_2.png‘, dpi=200)
#
import matplotlib as mpl
mpl.rcParams[‘figure.figsize‘]
mpl.rcParams[‘savefig.dpi‘]
mpl.reParams[‘Agg‘]

9 本小结所有代码示例

import matplotlib.pyplot as plt
plt.plot([1, 3, 2, 4])
plt.show()

import matplotlib.pyplot as plt
x = range(6)
plt.plot(x, [xi**2 for xi in x])
plt.show()

import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0.0, 6.0, 0.01)
plt.plot(x, [x**2 for x in x])
plt.show()

import matplotlib.pyplot as plt
import numpy as np
x = np.arange(1, 5)
plt.plot(x, x*1.5, x, x*3.0, x, x/3.0)
plt.grid(True)
plt.show()

import matplotlib.pyplot as plt
import numpy as np
x = np.arange(1, 5)
plt.plot(x, x*1.5, x, x*3.0, x, x/3.0)
plt.axis() # 显示当前坐标轴的极限取值范围 x->(0.85, 4.15), y->(-0.25, 12.58)
plt.axis([0, 5, -1, 13]) # 从新设置当前坐标轴的范围
plt.show()

import matplotlib.pyplot as plt
plt.plot([1, 3, 2, 4])
plt.xlabel(‘This is the X axis‘) #这个是x轴的标签
plt.ylabel(‘This is the Y axis‘) #这个是y轴的标签
plt.show()

import matplotlib.pyplot as plt
plt.plot([1, 3, 2, 4])
plt.title(‘Simple plot‘) # 图像的标题
plt.show()

import matplotlib.pyplot as plt
import numpy as np
x = np.arange(1, 5)
plt.plot(x, x*1.5, label="Normal")
plt.plot(x, x*3.0, label="Fast")
plt.plot(x, x/3.0, label="Slow")
plt.legend() # 设置图例
plt.show()

import matplotlib.pyplot as plt
import numpy as np
x = np.arange(1, 5)
plt.plot(x, x*1.5, x, x*3.0, x, x/3.0)
plt.grid(True)
plt.title(‘Sample Growth of a Measure‘)
plt.xlabel(‘Samples‘)
plt.ylabel(‘Values Measured‘)
plt.legend([‘Normal‘, ‘Fast‘, ‘Slow‘], loc = ‘upper left‘)
plt.show()

import matplotlib.pyplot as plt
plt.plot([1, 2, 3])
plt.savefig("plot123.png")
import matplotlib as mpl
mpl.rcParams[‘figure.figsize‘]
mpl.rcParams[‘savefig.dpi‘]
plt.savefig(‘plot123_2.png‘, dpi=200)

 



知识在于点点滴滴的积累,我会在这个路上Go ahead,

有幸看到我博客的朋友们,若能学到知识,请多多关注以及讨论,让我们共同进步,扬帆起航。

后记:打油诗一首

适度锻炼,量化指标

考量天气,设定目标

科学锻炼,成就体标

高效科研,实现学标


原文地址:https://www.cnblogs.com/brightyuxl/p/9251258.html

时间: 2024-08-30 15:30:16

Python3绘图之Matplotlib(01)的相关文章

Python 绘图包 Matplotlib Pyplot 教程

Pyplot 接口简介 Pyplot 入门 matplotlib.pyplot?是命令风格函数的集合,使 Matplotlib 像 MATLAB 一样工作.每个 Pyplot 函数对图形做一些修改,例如:创建一个图形,在图形中创建一个绘图区域,在绘图区域中回值一些线条,用标签装饰图形等等. 在?matplotlib.pyplot中,在函数调用之间保留了各种状态,以便跟踪当前图形和绘图区域等内容,绘图函数指向当前 轴(Axes 对象). 注意 Pyplot API 通常不如面向对象的 API 灵活

Windows7 x64系统上为python3.4 安装matplotlib

Windows 7 x64系统上为Python3.4导入matplotlib遇到一些问题,经查找最终得到解决方案: 下载Windows 64位系统下Python 3.4安装matplotlib所需的whl文件:(下载地址http://www.lfd.uci.edu/~gohlke/pythonlibs/) numpy-1.9.2cp34-none-win_amd64.whl scipy-0.16.0rc1-cp34-none-win_amd64.whl matplotlib-1.4.3-cp34

Python绘图工具matplotlib的安装

今天在机子上安装matplotlib遇到一些问题,特将此记录下来,供大家分享以少走弯路. 1:下载matplotlib 去官网上下载你所需要的版本http://matplotlib.org/download.html,  注意这里的32位和64位指的是python版本.由于是exe文件,直接安装即可. 2:import matplotlib 当我在python shell 中使用命令import matplotlib时出现了以下错误 此时我们需要安装dateutil,这里需要使用easy_ins

python3绘图示例6-2(基于matplotlib,绘图流程介绍及设置等)

#!/usr/bin/env python# -*- coding:utf-8 -*- import os import numpy as npimport matplotlib as mpltfrom matplotlib import pyplot as pltfrom matplotlib.ticker import * # 整个图像为1个figure对象,figure对象包含多个Axes对象,每个Axes对象都拥有自己坐标轴的绘图区域# 调用figure时,则调用plot,然后plot调

python3绘图示例2(基于matplotlib:柱状图、分布图、三角图等)

#!/usr/bin/env python# -*- coding:utf-8 -*- from matplotlib import pyplot as pltimport numpy as npimport pylab import os,sys,time,math,random # 图1-给已有的图加上刻度file=r'D:\jmeter\jmeter3.2\data\Oracle数据库基础.png'arr=np.array(file.getdata()).reshape(file.size

python3绘图示例4(基于matplotlib:箱线图、散点图等)

#!/usr/bin/env python# -*- coding:utf-8 -*- from matplotlib.pyplot import * x=[1,2,3,4]y=[5,4,3,2] # 创建新图标figure() # 对角线图 第1个参数:2行 第2个参数:3列的网格 第3个参数:图形在网格的位置subplot(231)plot(x,y) # 垂直柱状图subplot(232)bar(x,y) # 水平柱状图subplot(233)barh(x,y) # 堆叠柱状图-颜色间隔su

python3绘图示例1(基于matplotlib)

#!/usr/bin/env python# -*- coding:utf-8 -*- import numpy as npimport matplotlib.pyplot as pltimport jsonfrom decimal import Decimal # 保留浮点类型jstring='{"name":"pro","price":12.05}'str=json.loads(jstring,parse_float=Decimal)prin

python3绘图示例6-1(基于matplotlib,绘图流程介绍及设置等)

#!/usr/bin/env python# -*- coding:utf-8 -*- import os import pylab as pyimport numpy as npfrom matplotlib import pyplot as pltimport matplotlib as mplt # matplotlib.get_config() 获取当前配置# 用户matplotlib配置文件路径path=mplt.get_configdir()print(path) # 当前matpl

python3绘图示例3(基于matplotlib:折线图等)

#!/usr/bin/env python# -*- coding:utf-8 -*-from pylab import *from numpy import *import numpy # 数据点图-数据点平滑处理def moveing_average(ineterval,window_size): window=ones(int(window_size))/float(window_size) return convolve(ineterval,window,'same') t=linspa