栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

【不等宽、不标准子图的制作无标题】

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【不等宽、不标准子图的制作无标题】

持续更新ing,欢迎各位点赞关注哦!

祥帅的小屋

分罗万象,姿态万千。

31篇原创内容

公众号

1. 格式化不等宽子图

fig.add_gridspec(行数,列数,宽度比,长度比,坐标x,坐标y,子图宽度,子图高度,子图水平间距,子图竖直间距)

gs = fig.add_gridspec(2, 2,  width_ratios=(7, 2), height_ratios=(2, 7),

                      left=0.1, right=0.9, bottom=0.1, top=0.9

#                       ,wspace=0.05, hspace=0.05)

添加不等宽子图

ax = fig.add_subplot(gs[1, 0])

ax_histx = fig.add_subplot(gs[0, 0], sharex=ax)

ax_histy = fig.add_subplot(gs[1, 1], sharey=ax)

sharex=ax——共享x轴

sharey=ax——共享y轴

子图:与列表索引相同,含义如上图

Example 1

from __future__ import print_function, divisionimport numpy as npimport matplotlib as mplimport matplotlib.pyplot as plt%matplotlib inline# start with a square Figurefig = plt.figure(figsize=(8, 8))
# Add a gridspec with two rows and two columns and a ratio of 2 to 7 between# the size of the marginal axes and the main axes in both directions.# Also adjust the subplot parameters for a square plot.gs = fig.add_gridspec(2, 2,  width_ratios=(7, 2), height_ratios=(2, 7),                      left=0.1, right=0.9, bottom=0.1, top=0.9#                       ,wspace=0.05, hspace=0.05                     )
ax = fig.add_subplot(gs[1, 0])ax_histx = fig.add_subplot(gs[0, 0], sharex=ax)ax_histy = fig.add_subplot(gs[1, 1], sharey=ax)
# use the previously defined function# scatter_hist(x, y, ax, ax_histx, ax_histy)
plt.show()

Example 2

import matplotlib.pyplot as pltfrom matplotlib.gridspec import GridSpec

def format_axes(fig):    for i, ax in enumerate(fig.axes):        ax.text(0.5, 0.5, "ax%d" % (i+1), va="center", ha="center")        ax.tick_params(labelbottom=False, labelleft=False)
fig = plt.figure(constrained_layout=True)
gs = GridSpec(2,2, figure=fig)ax1 = fig.add_subplot(gs[0,0])# identical to ax1 = plt.subplot(gs.new_subplotspec((0, 0), colspan=3))ax2 = fig.add_subplot(gs[1,0])ax3 = fig.add_subplot(gs[:,1])# ax4 = fig.add_subplot(gs[-1, 0])# ax5 = fig.add_subplot(gs[-1, -2])
fig.suptitle("GridSpec")format_axes(fig)
plt.show()

2. 任意位置,任意尺寸

fig.add_axes([坐标x,坐标y,子图宽度,子图高度])

axes = fig.add_axes([0.2, 0.2, 0.3, 0.3]) 

内参——列表:# left, bottom, width, height (range 0 to 1)

axes2 = fig.add_axes([0.4, 0.6, 0.3, 0.3]) # inset axes​​​​​​​

%matplotlib autoimport matplotlib.pyplot as pltfrom pylab import *x = linspace(0, 5, 10)y = x ** 2
fig = plt.figure()

axes = fig.add_axes([0.2, 0.2, 0.3, 0.3]) # left, bottom, width, height (range 0 to 1)axes2 = fig.add_axes([0.4, 0.6, 0.3, 0.3]) # inset axes
axes.plot(x, y, 'r')
axes.set_xlabel('x')axes.set_ylabel('y')axes.set_title('title')
# insertaxes2.plot(y, x, 'g')axes2.set_xlabel('y')axes2.set_ylabel('x')axes2.set_title('insert title');
plt.show()

电脑小技巧

运行——win+R,然后

msconfig——》设置开机启动配置
       dxdiag——》查看电脑软硬件信息

control——》打开控制面板

求关注!   

 

Matplotlib实现标记箭头随着线的方向走

Matlab作图笔记

Python的类和对象

Python绘制误差曲线图

使用python进行数据相关性分析

Matplotlib关于字体及子图的详细操作

Matplotlib曲线分段拟合与细节处理

Jupyter notebook的扩展插件

图内内嵌图和水平柱状图--科研美图

Matplotlib--在图像中使用LaTex公式及标注箭头的使用

孟祥帅创作

Email: 19966590832@189.cn

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/920978.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号