- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试绘制一些子图,但似乎无法共享轴。我看过其他代码,他们似乎完全按照我的尝试做,但我的似乎没有做任何事情。
我只是想在左侧的四个子图中共享各自的轴,同时将最右侧的子图分开。
nhập numpy dưới dạng np
nhập matplotlib.pyplot dưới dạng plt
# set the data
x_data = np.linspace(0, 10)
y_data_1 = np.sin(x_data)
y_data_2 = np.cos(x_data)
y_data_3 = [i / 2 for i in y_data_1]
y_data_4 = [j / 2 for j in y_data_2]
# make the plot
ax1 = plt.subplot(2,3,1)
plt.plot(x_data, y_data_1)
ax2 = plt.subplot(2,3,2, sharey=ax1)
plt.plot(x_data, y_data_1)
plt.plot(x_data, y_data_2)
ax3 = plt.subplot(1,3,3)
plt.plot(x_data)
ax4 = plt.subplot(2,3,4, sharex=ax1)
plt.plot(x_data, y_data_1)
plt.plot(x_data, y_data_2)
plt.plot(x_data, y_data_3)
ax5 = plt.subplot(2,3,5, sharex=ax2, sharey=ax4)
plt.plot(x_data, y_data_1)
plt.plot(x_data, y_data_2)
plt.plot(x_data, y_data_3)
plt.plot(x_data, y_data_4)
plt.hiển thị()
1 Câu trả lời
您快到了。您正在正确共享轴,但需要使某些子图的轴不可见(按照 Shared Axis Demo 的指示):
plt.setp(ax1.get_xticklabels(), visible=False)
# make the plot
ax1 = plt.subplot(2, 3, 1)
plt.plot(x_data, y_data_1)
plt.setp(ax1.get_xticklabels(), visible=False)
ax2 = plt.subplot(2, 3, 2, sharey=ax1)
plt.plot(x_data, y_data_1)
plt.plot(x_data, y_data_2)
plt.setp(ax2.get_xticklabels(), visible=False)
plt.setp(ax2.get_yticklabels(), visible=False)
ax3 = plt.subplot(1, 3, 3)
plt.plot(x_data)
ax4 = plt.subplot(2, 3, 4, sharex=ax1)
plt.plot(x_data, y_data_1)
plt.plot(x_data, y_data_2)
plt.plot(x_data, y_data_3)
ax5 = plt.subplot(2, 3, 5, sharex=ax2, sharey=ax4)
plt.plot(x_data, y_data_1)
plt.plot(x_data, y_data_2)
plt.plot(x_data, y_data_3)
plt.plot(x_data, y_data_4)
plt.setp(ax5.get_yticklabels(), visible=False)
plt.hiển thị()
.subplots()
功能以提高代码的可读性/简单性,例如:
f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, sharex='col', sharey='row')
关于python - plt.subplot 轴共享不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46063284/
我有点不清楚如何subplot作品。具体来说subplot(121)有什么区别和 subplot(1,2,1)在 MATLAB 中?我试图搜索 subplot文档,但我似乎找不到我要找的东西。 最佳答
我是编码方面的新手,因此也是 Python 方面的新手,所以这听起来可能很愚蠢,但是 Python 中 matplotlib 的 .subplot() 和 .subplots() 方法之间的主要区别是
def plot_it(U1, U2, x, i): fig_1, = plt.plot(x, U1) fig_2, = plt.plot(x, U2) i = str(int
有时候想要把几张图放在一起plot,比较好对比,subplot和subplots都可以实现,具体对比可以查看参考博文。这里用matplotlib库的subplot来举个栗子。 数据长什么样 有两
在matplotlib中,用subplots画子图时,有时候需要调整子图间矩,包括子图与边框的间矩,子图间上下间矩,子图间左右间矩,可以使用fig.tight_layout()函数:
如下所示: matplotlib subplots 设置总图的标题 : fig.suptitle(dname,fontsize=16,x=0.53,y=1.05,) 以上这篇matplotli
我不知道如何使用 R 和 Plotly 使表格子图正常工作。 下面演示了我的意思。我有两张图,一张散点图和一张 table 。使用 subplot 函数,表格图的行为不符合预期。 我要么在散点图上失去
我正在尝试绘制一些子图,但似乎无法共享轴。我看过其他代码,他们似乎完全按照我的尝试做,但我的似乎没有做任何事情。 我只是想在左侧的四个子图中共享各自的轴,同时将最右侧的子图分开。 import num
我想在子图的底部添加一个图例(2 x 2): 正如您所看到的,由于我手动调整了第二行中的图表,因此被挤压了一点。 是否有像 sublegend(...) 这样的函数,或者它是否涉及大量编码? 来源 这
在使用 Matplotlib 绘图时,我们大多数情况下,需要将一张画布划分为若干个子区域,之后,我们就可以在这些区域上绘制不用的图形。在本节,我们将学习如何在同一画布上绘制多个子图。 matplotl
matplotlib.pyplot模块提供了一个 subplots() 函数,它的使用方法和 subplot() 函数类似。其不同之处在于,subplots() 既创建了一个包含子图区域的画布,又创建
使用 plotly 的 subplots() 时,如何删除图例中的重复项? 这是我的 MWE: library(plotly) library(ggplot2) library(tidyr) mpg
如何调整某些子图之间的空白?在下面的示例中,假设我想消除第 1 个和第 2 个子图之间以及第 3 个和第 4 个之间的所有空白,并增加第 2 个和第 3 个之间的空间? import matplotl
如果我绘制如下所示的单个图表,其大小将为 (x * y)。 import matplotlib.pyplot as plt plt.plot([1, 2], [1, 2]) 但是,如果我在同一行中绘制
我需要在网格中显示20张图像,我的代码如下 def plot_matric_demo(img, nrows, ncols): fig, ax = plt.subplots(nrows=nrow
这个问题在这里已经有了答案: How to plot in multiple subplots (12 个答案) 关闭去年。 我在一些帮助下构建了一组饼图 Insert image into pie
我正在寻找一种方法来创建一个包含多个子图的绘图 fig, (ax0, ax1) = plt.subplots(nrows=2, sharex=True) 会在 matplotlib 中执行,然后可以通
当我使用 PyPlot 的 figure() 函数创建单个绘图时,我可以使用字符串作为参数来设置出现窗口的名称: import matplotlib.pyplot as plt figure = pl
我想要一个由四个子图组成的图形。其中两个是通常的线图,其中两个是 imshow-images。 我可以将 imshow-images 格式化为正确的绘图本身,因为它们中的每一个都需要自己的颜色条、修改
我在使用 plt.subplots 时尝试更改图形大小时遇到了一些麻烦。使用下面的代码,我只得到标准尺寸的图表,其中包含我所有的子图(大约有 100 个),并且显然只是一个额外的空 figures
Tôi là một lập trình viên xuất sắc, rất giỏi!