[英]How to make that subplots created in a for loop share the same scale and xticks (matplotlib)
I have the following code snippet, to create 20 subplots, showing a line, with different markers.我有以下代码片段,用于创建 20 个子图,显示一条线,带有不同的标记。 However, in y axis don't show the same scale, and they take part of some subplots, which makes the entire figure to look ugly.
但是,在 y 轴上没有显示相同的比例,并且它们占据了一些子图的一部分,这使得整个图看起来很难看。
import matplotlib.pyplot as plt
markers = [".", ",", "o","v","^","<",">","s","p","P","*","h","H","+","x","X","D","d", "|", "_"]
num_subplots = len(markers)
fig = plt.figure()
for i, j in zip(range(num_subplots), markers):
try:
i +=1
data = np.random.random(10)
ax = fig.add_subplot(5,5,i)
ax.plot(data, marker = j)
except Exception as e:
print(e)
I found in this post some information regarding the sharex argument, which is useful, however I cannot implement this idea in a loop.我在这篇文章中发现了一些关于 sharex 参数的信息,这很有用,但是我无法在循环中实现这个想法。
How to set same scale for subplots in python using matplotlib 如何使用 matplotlib 为 python 中的子图设置相同的比例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.