莫烦Matplotlib可视化第四章多图合并显示代码学习

4.1Subplot多合一显示

import  matplotlib.pyplot as plt
import numpy as npplt.figure()
"""
每个图占一个位置
"""
# plt.subplot(2,2,1)  #将画板分成两行两列,选取第一个位置,可以去掉逗号
# plt.plot([0,1],[0,1])
#
# plt.subplot(2,2,2)
# plt.plot([0,1],[0,1])
#
# plt.subplot(2,2,3)
# plt.plot([0,1],[0,1])
#
# plt.subplot(2,2,4)
# plt.plot([0,1],[0,1])
"""
第一个图独占一行
"""
plt.subplot(2,1,1)
plt.plot([0,1],[0,1])plt.subplot(2,3,4)
plt.plot([0,1],[0,1])plt.subplot(2,3,5)
plt.plot([0,1],[0,1])plt.subplot(2,3,6)
plt.plot([0,1],[0,1])plt.show()

4.2Subplot分格显示

import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
"""
三种不同的subplot显示方法
"""# #第一种:subplot2grid
# plt.figure()
# ax1 = plt.subplot2grid((3,3),(0,0),colspan=3,rowspan=1) #3行3列起始点是0.0,跨度是一行三列
# ax1.plot([1,2],[1,2])
# ax1.set_title('ax1_title')
# ax2 = plt.subplot2grid((3,3),(1,0),colspan=2,rowspan=1) #3行3列起始点是0.0,跨度是一行三列
# ax3 = plt.subplot2grid((3,3),(1,2),colspan=1,rowspan=2)
# ax4 = plt.subplot2grid((3,3),(2,0),colspan=1,rowspan=1)
# ax5 = plt.subplot2grid((3,3),(2,1),colspan=1,rowspan=1)# #第二种:gridspec
# plt.figure()
# gs = gridspec.GridSpec(3,3)
# ax6 = plt.subplot(gs[0,:])
# ax7 = plt.subplot(gs[1,:2]) #第一行占了前两个列
# ax8 = plt.subplot(gs[1:,2]) #第一行之后,占第二个列
# ax9 = plt.subplot(gs[-1,0])
# ax10 = plt.subplot(gs[-1,-2])#第三钟:define structure
f, ((ax11,ax12),(ax21,ax22)) = plt.subplots(2,2,sharex = True,sharey=True)  #sharex共享X轴
ax11.scatter ([1,2],[1,2])plt.tight_layout()
plt.show()

4.3图中图

import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspecfig = plt.figure()
x = [1,2,3,4,5,6,7]
y = [1,3,4,2,5,8,6]left,bottom,width,height = 0.1,0.1,0.8,0.8
ax1 = fig.add_axes([left,bottom,width,height])
ax1.plot(x,y,'r')
ax1.set_xlabel('x')
ax1.set_ylabel('y')
ax1.set_title('title')left,bottom,width,height = 0.2,0.6,0.25,0.25
ax2 = fig.add_axes([left,bottom,width,height])
ax1.plot(x,y,'b')
ax1.set_xlabel('x')
ax1.set_ylabel('y')
ax1.set_title('title inside 1')#第二种画图方法
plt.axes([0.6,0.2,0.25,0.25])
plt.plot(y[::-1],x,'g')
plt.xlabel('x')
plt.ylabel('y')
plt.title('title inside 2')plt.show()

4.4 主次坐标轴

import matplotlib.pyplot as plt
import numpy as npx = np.arange(0,10,0.1)
y1 = 0.05*x**2
y2 = -1*y1fig,ax1 = plt.subplots()
ax2 = ax1.twinx()   #镜面Y1轴
ax1.plot(x,y1,'g-')
ax2.plot(x,y2,'b--')ax1.set_xlabel('X data')
ax1.set_ylabel('Y1',color = 'g')
ax2.set_ylabel('Y2',color = 'b')plt.show()

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/389407.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python 网页编程_通过Python编程检索网页

python 网页编程The internet and the World Wide Web (WWW), is probably the most prominent source of information today. Most of that information is retrievable through HTTP. HTTP was invented originally to share pages of hypertext (hence the name Hypertext T…

Python+Selenium自动化篇-5-获取页面信息

1.获取页面title title:获取当前页面的标题显示的字段from selenium import webdriver import time browser webdriver.Chrome() browser.get(https://www.baidu.com) #打印网页标题 print(browser.title) #输出内容:百度一下,你就知道 2.…

火种 ctf_分析我的火种数据

火种 ctfOriginally published at https://www.linkedin.com on March 27, 2020 (data up to date as of March 20, 2020).最初于 2020年3月27日 在 https://www.linkedin.com 上 发布 (数据截至2020年3月20日)。 Day 3 of social distancing.社会疏离的第三天。 As I sit on…

莫烦Matplotlib可视化第五章动画代码学习

5.1 Animation 动画 import numpy as np import matplotlib.pyplot as plt from matplotlib import animationfig,ax plt.subplots()x np.arange(0,2*np.pi,0.01) line, ax.plot(x,np.sin(x))def animate(i):line.set_ydata(np.sin(xi/10))return line,def init():line.set…

data studio_面向营销人员的Data Studio —报表指南

data studioIn this guide, we describe both the theoretical and practical sides of reporting with Google Data Studio. You can use this guide as a comprehensive cheat sheet in your everyday marketing.在本指南中,我们描述了使用Google Data Studio进行…

人流量统计系统介绍_统计介绍

人流量统计系统介绍Its very important to know about statistics . May you be a from a finance background, may you be data scientist or a data analyst, life is all about mathematics. As per the wiki definition “Statistics is the discipline that concerns the …

pyhive 连接 Hive 时错误

一、User: xx is not allowed to impersonate xxx 解决办法&#xff1a;修改 core-site.xml 文件&#xff0c;加入下面的内容后重启 hadoop。 <property><name>hadoop.proxyuser.xx.hosts</name><value>*</value> </property><property…

乐高ev3 读取外部数据_数据就是新乐高

乐高ev3 读取外部数据When I was a kid, I used to love playing with Lego. My brother and I built almost all kinds of stuff with Lego — animals, cars, houses, and even spaceships. As time went on, our creations became more ambitious and realistic. There were…

图像灰度化与二值化

图像灰度化 什么是图像灰度化&#xff1f; 图像灰度化并不是将单纯的图像变成灰色&#xff0c;而是将图片的BGR各通道以某种规律综合起来&#xff0c;使图片显示位灰色。 规律如下&#xff1a; 手动实现灰度化 首先我们采用手动灰度化的方式&#xff1a; 其思想就是&#…

分析citibike数据eda

数据科学 (Data Science) CitiBike is New York City’s famous bike rental company and the largest in the USA. CitiBike launched in May 2013 and has become an essential part of the transportation network. They make commute fun, efficient, and affordable — no…

jvm感知docker容器参数

docker中的jvm检测到的是宿主机的内存信息&#xff0c;它无法感知容器的资源上限&#xff0c;这样可能会导致意外的情况。 -m参数用于限制容器使用内存的大小&#xff0c;超过大小时会被OOMKilled。 -Xmx: 默认为物理内存的1/4。 4核CPU16G内存的宿主机 java 7 docker run -m …

Flask之flask-script 指定端口

简介 Flask-Scropt插件为在Flask里编写额外的脚本提供了支持。这包括运行一个开发服务器&#xff0c;一个定制的Python命令行&#xff0c;用于执行初始化数据库、定时任务和其他属于web应用之外的命令行任务的脚本。 安装 用命令pip和easy_install安装&#xff1a; pip install…

上采样(放大图像)和下采样(缩小图像)(最邻近插值和双线性插值的理解和实现)

上采样和下采样 什么是上采样和下采样&#xff1f; • 缩小图像&#xff08;或称为下采样&#xff08;subsampled&#xff09;或降采样&#xff08;downsampled&#xff09;&#xff09;的主要目的有 两个&#xff1a;1、使得图像符合显示区域的大小&#xff1b;2、生成对应图…

r语言绘制雷达图_用r绘制雷达蜘蛛图

r语言绘制雷达图I’ve tried several different types of NBA analytical articles within my readership who are a group of true fans of basketball. I found that the most popular articles are not those with state-of-the-art machine learning technologies, but tho…

java 分裂数字_分裂的补充:超越数字,打印物理可视化

java 分裂数字As noted in my earlier Nightingale writings, color harmony is the process of choosing colors on a Color Wheel that work well together in the composition of an image. Today, I will step further into color theory by discussing the Split Compleme…

Java 集合 之 Vector

http://www.verejava.com/?id17159974203844 import java.util.ArrayList; import java.util.Enumeration; import java.util.List; import java.util.Vector;public class Test {/*** param args the command line arguments*/public static void main(String[] args) {//打印…

前端电子书单大分享~~~

前言 纯福利&#xff0c; 如果你不想买很多书&#xff0c;只想省钱看电子书&#xff1b; 如果你找不到很多想看书籍的电子书版本&#xff1b; 那么&#xff0c;请保存或者下载到自己的电脑或者手机或者网盘吧。 不要太着急&#xff0c;连接在最后呢 前端 前端框架 node html-cs…

结构化数据建模——titanic数据集的模型建立和训练(Pytorch版)

本文参考《20天吃透Pytorch》来实现titanic数据集的模型建立和训练 在书中理论的同时加入自己的理解。 一&#xff0c;准备数据 数据加载 titanic数据集的目标是根据乘客信息预测他们在Titanic号撞击冰山沉没后能否生存。 结构化数据一般会使用Pandas中的DataFrame进行预处理…

比赛,幸福度_幸福与生活满意度

比赛,幸福度What is the purpose of life? Is that to be happy? Why people go through all the pain and hardship? Is it to achieve happiness in some way?人生的目的是什么&#xff1f; 那是幸福吗&#xff1f; 人们为什么要经历所有的痛苦和磨难&#xff1f; 是通过…

带有postgres和jupyter笔记本的Titanic数据集

PostgreSQL is a powerful, open source object-relational database system with over 30 years of active development that has earned it a strong reputation for reliability, feature robustness, and performance.PostgreSQL是一个功能强大的开源对象关系数据库系统&am…