Python,Matplotlib,绘制不规则网格 [英] Python, Matplotlib, plotting irregular grid

查看:126
本文介绍了Python,Matplotlib,绘制不规则网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Matplotlib 中,我试图绘制以下网格:

In Matplotlib, I am trying to plot the following grid:

以下公式为我提供了每一行的长度:

The following formula gives me the length of each row:

xlen_max = 4
ylen = 7
for g in range(ylen):
    xlen = min(ylen-g, xlen_max)
    print(xlen)
4
4
4
4
3
2
1

我尝试将它应用到 matplotlib 中:

I try to apply it to matplotlib as such:

fig, axes = plt.subplots(ylen, xlen_max , figsize=(5, 5))
for aa, axlist[aa] in enumerate(axes):
    for a, ax in enumerate(axlist[aa]):
        xlen = min(ylen-g, xlen_max)
        if xlen > a  :
            axlist[aa][a].axis('off')

或对此进行修改,但这会返回各种错误和/或形状怪异的绘图网格..作为一个快速的想法/建议/提示,任何人都可能是前进的方向吗?

Or variations on that, but this returns various error and/or weird shaped plot grid.. Anyone as a quick idea/suggestion/hint what could be the way forward?

推荐答案

您可以使用 axe.set_visible(False) 将不需要的轴设置为不可见.下面是一个例子:

You can use axe.set_visible(False) to set invisible the axes that you don't need. Here is a example:

cnt = 1
fig, axes = plt.subplots(7, 4 , figsize=(5, 5))
for i, row in enumerate(axes):
    for j, axe in enumerate(row):
        if i > 3:
            if j > 3 - cnt:
                axe.set_visible(False)
    if i > 3:
        cnt += 1 

这篇关于Python,Matplotlib,绘制不规则网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆