1

In Matplotlib, I am trying to plot the following grid: enter image description here

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

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?

1 Answer 1

1

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 

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

That's awesome thanks! What is the difference between axe.set_visible(False) and axe.axis('off') ?
I can not find a difference between the two. The result is the same.
axe.axis('off') just turns the axis lines, ticks and labels off. axe.set_visible(False) hides the whole axes artist, including anything plotted on it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.