[英]Vertical arrangement in matplotlib subplots
I am trying to plot a figure with 4 subplots.我正在尝试 plot 一个带有 4 个子图的图形。 The following code is similar to what I have written.
下面的代码和我写的差不多。
import numpy as np
import matplotlib.pyplot as plt
def trial(x, r, ax=None):
y = r*np.sin(x)
ax[0].plot(x, r*x)
ax[0].set_title('x')
ax[1].plot(x, y)
ax[1].set_title('sinx')
x = np.linspace(0, 4*np.pi)
fig, (ax1, ax2) = plt.subplots(2,2)
trial(x, 1, ax1)
trial(x, 2, ax2)
This is the output I get.这是我得到的 output。
If I only plot ax1(after removing last index from subplots), x and sin(x) are vertically arranged.如果我只有 plot ax1(从子图中删除最后一个索引后),x 和 sin(x) 是垂直排列的。 But as soon as I add ax2, they become horizontally arranged.
但是一旦我添加 ax2,它们就会水平排列。 I want x and sin(x) to be vertically arranged with both ax1 and ax2.
我希望 x 和 sin(x) 与 ax1 和 ax2 垂直排列。 What correction should I make?
我应该做什么更正?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.