当前位置: 首页 > news >正文

python学习——Matplotlib库的基础

Matplotlib

简要说明:由jupyter notebook导入,运行结果紧随代码

import matplotlib.pyplot as plt
import numpy as np
from matplotlib_inline import backend_inline
backend_inline.set_matplotlib_formats('svg')
%matplotlib inline
fig1 = plt.figure() # 创建新图窗
x = [1,2,3,4,5]
y = [1,8,27,64,125]
plt.plot(x,y) # 描点连线
plt.bar(x,y)
<BarContainer object of 5 artists>

在这里插入图片描述

fig1.savefig(r'D:\Study\test.svg')
fig2 = plt.figure()
# ax2 = plt.axes()
x = [1,2,3,4,5]
y1 = [1,2,3,4,5]
y2 = [0,0,0,0,0]
y3 = [-1,-2,-3,-4,-5]
plt.plot(x,y1,label='y1')
plt.plot(x,y2,label='y2')
plt.plot(x,y3)
plt.legend(frameon=False,ncol=2,loc='best')
plt.grid(color='red',linestyle='--')
# ax2.plot(x,y1)
# ax2.plot(x,y2)
# ax2.plot(x,y3)

在这里插入图片描述

fig3 = plt.figure()
x = [1,2,3,4,5]
y1 = [1,2,3,4,5]
y2 = [0,0,0,0,0]
y3 = [-1,-2,-3,-4,-5]
plt.subplot(3,1,1),plt.plot(x,y1)
plt.subplot(3,1,2),plt.plot(x,y2)
plt.subplot(3,1,3),plt.plot(x,y3)
(<Axes: >, [<matplotlib.lines.Line2D at 0x22df0185400>])

在这里插入图片描述

fig4 = plt.figure()
x = [1,2,3,4,5]
y1 = [1,2,3,4,5]
y2 = [0,0,0,0,0]
y3 = [-1,-2,-3,-4,-5]
y4 = [2,3,4,5,6]
y5 = [-2,-3,-4,-5,-6]
plt.plot(x,y1,color='red',linestyle='-',linewidth=4,marker='o',markersize=5)
plt.plot(x,y2,color='blue',linestyle='--', linewidth=1.5,marker='s',markersize=5)
plt.plot(x,y3,color='green',linestyle='-.', linewidth=1, marker='D',markersize=5)
plt.plot(x,y4,color='yellow',linestyle=':', linewidth=1.5,marker='.',markersize=5)
plt.plot(x,y5,color='purple',linestyle='', linewidth=3,marker='^',markersize=5) # 绘制散点图
plt.legend(['y1','y2','y3','y4','y5'])

在这里插入图片描述

<matplotlib.legend.Legend at 0x22df6012400>
x6 = np.linspace(0,10,1000)
I = np.sin(x6)*np.cos(x6).reshape(-1,1)
fig5 = plt.figure()
plt.imshow(I)
plt.colorbar()
<matplotlib.colorbar.Colorbar at 0x22df11e0f10>

在这里插入图片描述

x11 = np.random.normal(3,1,1000)
x12 = np.random.normal(6,1,1000)
x13 = np.random.normal(9,1,1000)
fig6 = plt.figure()
plt.hist(x11,bins=30,alpha=1,histtype='stepfilled',color='blue',edgecolor='yellow',linewidth=2)
plt.hist(x12,bins=30,alpha=0.5,histtype='stepfilled',color='red',edgecolor='yellow',linewidth=2)
plt.hist(x13,bins=30,alpha=0.5,histtype='stepfilled',color='purple',edgecolor='yellow',linewidth=2)
(array([ 3.,  3.,  6.,  8., 12., 16., 29., 42., 49., 51., 67., 71., 76.,95., 89., 60., 77., 59., 54., 43., 33., 22.,  7., 10.,  8.,  1.,5.,  2.,  0.,  2.]),array([ 6.04959894,  6.2639757 ,  6.47835246,  6.69272921,  6.90710597,7.12148273,  7.33585949,  7.55023624,  7.764613  ,  7.97898976,8.19336652,  8.40774327,  8.62212003,  8.83649679,  9.05087355,9.26525031,  9.47962706,  9.69400382,  9.90838058, 10.12275734,10.33713409, 10.55151085, 10.76588761, 10.98026437, 11.19464112,11.40901788, 11.62339464, 11.8377714 , 12.05214815, 12.26652491,12.48090167]),[<matplotlib.patches.Polygon at 0x22df5415550>])

在这里插入图片描述

fig7 = plt.figure() # 创建新图窗
x22 = [1,2,3,4,5]
y22 = [1,8,27,64,125]
plt.plot(x22,y22) # 描点连线
plt.xlim(1,5)
plt.ylim(1,100)
plt.title('This is the title')
plt.xlabel('This is the xlabel')
plt.ylabel('This is the ylabel')
# plt.axis([1,5,1,50])
#plt.axis('equal')
Text(0, 0.5, 'This is the ylabel')

在这里插入图片描述

http://www.dtcms.com/a/277697.html

相关文章:

  • 4. MyISAM vs InnoDB:深入解析MySQL两大存储引擎
  • c语言进阶 深度剖析数据在内存中的存储
  • Spring-----MVC配置和基本原理
  • Opencv---blobFromImage
  • macos安装iper3
  • Java面试(基础题)-第一篇!
  • C++模版编程:类模版与继承
  • QCustomPlot绘图结合滑动条演示
  • anaconda常用命令
  • 第一个Flink 程序 WordCount,词频统计(批处理)
  • 从架构到代码:飞算JavaAI电商订单管理系统技术解构
  • 关键点检测 roboflow 折弯识别
  • 从“被动巡检”到“主动预警”:塔能物联运维平台重构路灯管理模式
  • Word 文字编辑状态下按回车换行后是非正文格式
  • 【LeetCode 热题 100】23. 合并 K 个升序链表——(解法一)逐一合并
  • FastAPI快速构建完成一个简单的demo,(curd)
  • 深入理解 Java JVM
  • BERT系列模型
  • Spring Boot 配置注解处理器 - spring-boot-configuration-processor
  • Python I/O 库【输入输出】全面详解
  • JavaScript加强篇——第九章 正则表达式高级应用(终)
  • Python __main__ 全面深度解析
  • C++ 右值引用和移动语义的应用场景
  • python的平安驾校管理系统
  • Python自动化:每日销售数据可视化
  • Linux-线程控制
  • System.getenv()拿不到你配置的环境变量
  • 【Mysql作业】
  • OSPF协议特性
  • kettle从入门到精通 第九十七课 ETL之kettle kettle资源仓库的5种方式