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

matplotlib

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

matplotlib

您提供的代码似乎产生了预期的结果。

这使我认为您的控制台或matplotlib版本存在问题-也许您可以提供有关如何运行代码的更多信息。

我建议移动

ax.set_xlabel
之前
twinx
,例如:

ax_2 = fig.add_subplot(222, sharex=None, sharey=None)ax_22 = ax_2.twinx()ax_2.set_xlabel("AX2 X Lablel")ax_2.plot([1, 3, 5, 7, 9])# Becomes...ax_2 = fig.add_subplot(222, sharex=None, sharey=None)ax_2.set_xlabel("AX2 X Lablel")ax_2.plot([1, 3, 5, 7, 9])ax_22 = ax_2.twinx()

编辑
我建议改用gridspec。请参见以下工作示例:

import matplotlib.pyplot as pltimport matplotlib.gridspec as gspecimport numpy as npfig = plt.figure()gs = gspec.GridSpec(2, 2)gs.update(hspace=0.7, wspace=0.7)ax1 = plt.subplot(gs[0, 0])ax2 = plt.subplot(gs[1, 0])ax3 = plt.subplot(gs[0, 1])ax4 = plt.subplot(gs[1, 1])x1 = np.linspace(1,10,10)ax1.plot(x1, x1**2)ax1.set_xlabel('ax1 x')ax1_2 = ax1.twinx()ax1_2.plot(x1, x1**3)ax1_2.set_ylabel('ax1_2 y')ax1.set_ylabel('ax1 y')# To save time I left the other cells blank, but it should work fine.plt.show()

上面产生了这个:



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

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

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