Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make only left subplots and bottom subplots (in MxN panels) contain x and y axis labels

Is there any way in a panel of NxM subplots to just have the axes being shown for the left column and bottom row.

A|N|N|N
A|N|N|N
A|N|N|N
A|A|A|A

Where A = axis and N = no axis

Sometimes my subplots are 10x8, 3x4, 4x9 etc. and they all have the same x and y axis. I just want it to appear on the very left and the very bottom of that subset. At the moment I have to know which axis it is plotting to and do

    if (figi-1) % 7 != 0:
        ax.set_yticklabels([])

    if figi < 29:
        ax1.set_xticklabels([])

I want to generalise this for any NxM panel arrangement without having to know before hand. Thanks.

EDIT: I have found a way to do the y-axis. I setup the number of panels wide using:

nwide = 12
nhigh = 5

Which means I can just do

if (figi-1) % nwide != 0:
    ax.set_yticklabels([])

Any ideas for bottom?

EDIT: Worked it out. x-axis is as follows:

if figi < (nwide*nhigh) - nwide:
    ax.set_xticklabels([])
like image 695
Griff Avatar asked Jun 19 '13 17:06

Griff


1 Answers

The best solution is probably pyplot.subplots(). You can do like:

fig, axes = pyplot.subplots(nrows=3, ncols=4, sharex=True, sharey=True)

enter image description here

and then only the left and bottom axes will have the labels displayed.

To access each subplot you can get it from axes like you do in a matrix: ax = axes[i,j]

To control the tick positions you can use:

ax.xaxis.set_tick_position('bottom')
ax.yaxis.set_tick_position('left')

To set an axis label you can do:

ax.set_label_text('Something')
like image 59
Saullo G. P. Castro Avatar answered Sep 21 '22 01:09

Saullo G. P. Castro