Matplotlib - 网格排列子图间距
我正在尝试像时尚一样将一堆子图排列在网格中。问题在于,子图的数量随着用户选择绘制的数据而变化。现在我正在尝试以这种方式添加绘图:
l = len(clicked)
self.p=wx.Panel(self)
self.dpi=100
self.fig = Figure()
self.canvas = FigCanvas(self.p, -1, self.fig)
if l == 1:
self.splt = self.fig.add_subplot(1,1,1)
self.plt=self.splt.plot(np.arange(5),np.arange(5))
else:
for i in np.arange(l):
self.splt=self.fig.add_subplot(l+1,2,i+1)
self.fig.subplots_adjust(left=0.7, bottom=0.6, right=0.75, top=0.75)
self.plt=self.splt.plot(np.arange(5),np.arange(5))
我只是使用假数据进行调试。无论如何,我正在使用 wxPython 在框架内绘制它。这里的clicked
提供了用户所做选择的数量。我已经尝试过使用 subplots_adjust() ,结果与我想要的完全相反。情节被缩小得难以辨认。有没有办法将绘图排列在某种网格中。我看到有一个选项 subplot2grid
,但我还没有让它处理可变数量的子图。
I am trying to arrange a bunch of subplots in a grid like fashion. The problem is that the number of subplots varies with user selection of what data to plot. Right now I am trying to add plots this way:
l = len(clicked)
self.p=wx.Panel(self)
self.dpi=100
self.fig = Figure()
self.canvas = FigCanvas(self.p, -1, self.fig)
if l == 1:
self.splt = self.fig.add_subplot(1,1,1)
self.plt=self.splt.plot(np.arange(5),np.arange(5))
else:
for i in np.arange(l):
self.splt=self.fig.add_subplot(l+1,2,i+1)
self.fig.subplots_adjust(left=0.7, bottom=0.6, right=0.75, top=0.75)
self.plt=self.splt.plot(np.arange(5),np.arange(5))
I am just using fake data for debugging purposes. Anyhow, I am using wxPython to draw this inside a frame. clicked
here provides the number of selections the user made. I already tried using subplots_adjust()
, with quite the opposite result than I wanted. The plots are being shrunk something indiscernable. Is there a way to arrange teh plots in some sort of grid. I saw there is an option subplot2grid
, but I havent gotten it to work with the variable number of subplots.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
希望这会有所帮助:
divideSquare(N) 尝试获得接近 1 的比率,但空仓数量最少。
divide2or3(N) 为您提供 2 或 3 列的网格(如果反转 x 和 y,则为行),但我不确定这是否是您想要的 90 个图。
Hopefully this helps:
divideSquare(N) attempts to get a ratio close to 1 but with a minimal number of empty positions.
divide2or3(N) gives you a grid of 2 or 3 columns (or rows if you invert x and y), but I'm not sure if this is what you want for 90 plots.