栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

MatPlotLib-子图的子图或单个图上的多个折断的轴图

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

MatPlotLib-子图的子图或单个图上的多个折断的轴图

首先,您无法创建子图的子图。子图是

axes
放置在图形中的对象,并且轴不能具有“子轴”。

解决您的问题的方法是创建6个子图并将其应用于

sharex=True
各个轴。

import matplotlib.pyplot as pltimport numpy as npdata = np.random.rand(17, 6)data[15:, 3:] = np.random.rand(2, 3)+3.markers=["o", "p", "s"]colors=["r", "g", "b"]fig=plt.figure(figsize=(10, 4))axes = []for i  in range(3):    ax = fig.add_subplot(2,3,i+1)    axes.append(ax)for i in range(3):    ax = fig.add_subplot(2,3,i+4, sharex=axes[i])    axes.append(ax)for i  in range(3):    # plot same data in both top and down axes    axes[i].plot(data[:,i], data[:,i+3], marker=markers[i], line, color=colors[i])    axes[i+3].plot(data[:,i], data[:,i+3], marker=markers[i], line, color=colors[i])for i  in range(3):    axes[i].spines['bottom'].set_visible(False)    axes[i+3].spines['top'].set_visible(False)    axes[i].xaxis.tick_top()    axes[i].tick_params(labeltop='off')  # don't put tick labels at the top    axes[i+3].xaxis.tick_bottom()    axes[i].set_ylim([3,4])    axes[i+3].set_ylim([0,1])    axes[i].set_xlim([0,1])#adjust space between subplotsplt.subplots_adjust(hspace=0.08, wspace=0.4)plt.show()



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

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

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