简体   繁体   English

同时创建多个matplotlib图表时如何显示网格?

[英]How to display the grid when multiple matplotlib charts are created at the same time?

I would like to use the grid in multiple matplotlib figures, but if I just use plt.grid() the grid would only show up in one of the charts.我想在多个 matplotlib 图中使用网格,但如果我只使用plt.grid()网格只会显示在其中一个图表中。

How can I change the code below, so that the grid shows up in both figures, please?请问如何更改下面的代码,以便网格显示在两个图中?

import matplotlib.pyplot as plt
import numpy as np

rng = np.random.default_rng(19680801)
N_points = 100000
dist1 = rng.standard_normal(N_points)

fig = plt.figure()
axis = fig.add_subplot(1,1,1)

fig1 = plt.figure()
ax = fig1.add_subplot(1,1,1)

axis.hist(dist1)

ax.hist(dist1)
plt.grid()
plt.show()
import matplotlib.pyplot as plt
import numpy as np

rng = np.random.default_rng(19680801)
N_points = 100000
dist1 = rng.standard_normal(N_points)

fig = plt.figure()
axis = fig.add_subplot(1,1,1)
axis.grid()
fig1 = plt.figure()
ax = fig1.add_subplot(1,1,1)
ax.grid()

axis.hist(dist1)

ax.hist(dist1)
# plt.grid()
plt.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM