<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small">Hi Eric et al.,</div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small">So I have confirmed that the thing that prevents label_outer from working the way I would expect it to is that after adding a colorbar to the subplot axes, the attributes colNum and rowNum are set to 0. Would you consider this a bug? I think I would. I'm thinking that it's because adding the colorbar creates a new set of axes into which the colorbar is placed. A minimal example that illustrates the issue is:</div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small">fig,axs = plt.subplots(1,2)</div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small">img0 = np.random.random((5,5))</div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small">img1 = np.random.random((5,5))</div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small">cax0 = axs[0].imshow(img0)</div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small">fig.colorbar(cax0,ax=axs[0])</div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small">cax1 = axs[1].imshow(img1)</div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small">print(f'axs[1].column = {axs[1].colNum}') # value is 1</div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small">fig.colorbar(cax1,ax=axs[1])</div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small">print(f'axs[1].column = {axs[1].colNum}') # values is 0<br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small">plt.show()</div></div><div><br></div><div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small">Jon</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Mar 20, 2020 at 2:56 PM Slavin, Jonathan <<a href="mailto:jslavin@cfa.harvard.edu" target="_blank">jslavin@cfa.harvard.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div style="font-family:tahoma,sans-serif;font-size:small">Hi Eric,</div><div style="font-family:tahoma,sans-serif;font-size:small"><br></div><div style="font-family:tahoma,sans-serif;font-size:small">I think I've isolated the problem. In my figure I have been including colorbars for each plot. In my simple example, which I include below, label_outer works without the colorbars but not with them. </div><div style="font-family:tahoma,sans-serif;font-size:small"><br></div><div style="font-family:tahoma,sans-serif;font-size:small">Regarding using sharey, I am using the same y-axis in each row, but they differ between rows. If I use sharey, things get all messed up - the smaller images are shrunken and only take up part of the figure. In the end I was able to turn off the tick labelling by doing things like:</div><div style="font-family:tahoma,sans-serif;font-size:small">for label in ax.get_yticklabels(which='both'):<br> label.set_visible(False)<br></div><div style="font-family:tahoma,sans-serif;font-size:small"><br></div><div style="font-family:tahoma,sans-serif;font-size:small">I think this may have to do with the attributes of axs getting overwritten or something. If I print</div><div style="font-family:tahoma,sans-serif;font-size:small">axs[1,1].get_subplotspec().colspan.start<br></div><div style="font-family:tahoma,sans-serif;font-size:small">in the case with colorbars I get 0, whereas if I do it without colorbars, I get 1 as I should. Same applies to other axes and to rows.</div><div style="font-family:tahoma,sans-serif;font-size:small"><br></div><div style="font-family:tahoma,sans-serif;font-size:small">Here's the minimal example:</div><div style="font-family:tahoma,sans-serif;font-size:small"><br></div>import numpy as np<br>import matplotlib.pyplot as plt<br><br>fig,axs = plt.subplots(2,2)<br>img0 = np.random.random((10,10))<br>img1 = np.random.random((10,10))<br>img2 = np.random.random((10,10))<br>img3 = np.random.random((10,10))<br>cax0 = axs[0,0].imshow(img0,extent=[0.,10.,0.,10.])<br>fig.colorbar(cax0,ax=axs[0,0],pad=0.01)<br>cax1 = axs[0,1].imshow(img1,extent=[0.,10.,0.,10.])<br>fig.colorbar(cax1,ax=axs[0,1],pad=0.01)<br>cax2 = axs[1,0].imshow(img2,extent=[0.,10.,0.,10.])<br>fig.colorbar(cax2,ax=axs[1,0],pad=0.01)<br>cax3 = axs[1,1].imshow(img3,extent=[0.,10.,0.,10.])<br>fig.colorbar(cax3,ax=axs[1,1],pad=0.01)<br>for ax in axs.flat:<br> ax.label_outer()<br><div style="font-family:tahoma,sans-serif;font-size:small"><span style="font-family:Arial,Helvetica,sans-serif">plt.show()</span><br></div><div style="font-family:tahoma,sans-serif;font-size:small"><br></div></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Mar 20, 2020 at 11:04 AM <<a href="mailto:matplotlib-users-request@python.org" target="_blank">matplotlib-users-request@python.org</a>> wrote:</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Date: Thu, 19 Mar 2020 12:42:31 -1000<br>
From: Eric Firing <<a href="mailto:efiring@hawaii.edu" target="_blank">efiring@hawaii.edu</a>><br>
To: <a href="mailto:matplotlib-users@python.org" target="_blank">matplotlib-users@python.org</a><br>
Subject: Re: [Matplotlib-users] trouble removing tick labels<br>
Message-ID: <<a href="mailto:77e44a65-c519-705e-24ad-dc13f7c204c3@hawaii.edu" target="_blank">77e44a65-c519-705e-24ad-dc13f7c204c3@hawaii.edu</a>><br>
Content-Type: text/plain; charset=utf-8; format=flowed<br>
<br>
Jon,<br>
<br>
If you are removing the tick labels it suggests that the y-axes are all <br>
matched, in which case using<br>
<br>
fig, axs = plt.subplots(2, 2, sharey=True)<br>
<br>
should do what you want.<br>
<br>
If not, please supply a minimal but complete example illustrating the <br>
problem.<br>
<br>
Eric<br>
<br>
On 2020/03/19 11:36 AM, Slavin, Jonathan wrote:<br>
> Hi,<br>
> <br>
> I'm making a plot that's a grid of 4 x 4 axes. I'd like to remove the <br>
> tick labels for the y axes that are not in the first column. I tried <br>
> using what I saw in an example:<br>
> for ax in axs.flat:<br>
> ? ? ax.label_outer()<br>
> but that seems to have no effect. I found where the code that defines <br>
> that function is and tried to use that code directly:<br>
> for ax in axs.flat:<br>
> ? ? if ax.colNum != 0:<br>
> ? ? ? ? for label in ax.get_yticklabels(which='both'):<br>
> ? ? ? ? ? ? label.set_visible(False)<br>
> ? ? ? ? ax.get_yaxis().get_offset_text().set_visible(False)<br>
> ? ? ? ? ax.set_ylabel("")<br>
> but again no effect. Does anyone have any ideas why these are not <br>
> working? Any help would be appreciated.<br>
> <br>
> Regards,<br>
> Jon<br></blockquote></div>-- <br><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><img src="https://lh6.googleusercontent.com/mJuf9zI6QC5w6HPVCinnLSkpp-RgufOfl7nw1E_aghDflNhusoRbZTuP_0x-RkECQRhIfvPxGMe6zSt6chyXZ7D5DdqtkZPp0q-TE8itKny8VWObWAiZ1aurYWDO0CtZgvJEXfzu" width="350" height="2" style="font-size:12.6667px;font-family:Arial;white-space:pre-wrap;border:none"></div><div dir="ltr">Jonathan D. Slavin</div><div dir="ltr">Astrophysicist - High Energy Astrophysics Division</div><div dir="ltr">Center for Astrophysics | Harvard & Smithsonian</div><div dir="ltr">Office: (617) 496-7981 | Cell: (781) 363-0035<br>60 Garden Street | MS 83 | Cambridge, MA 02138</div></div><div dir="ltr"><span><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt"><span style="font-size:9.5pt;font-family:Arial;background-color:transparent;vertical-align:baseline;white-space:pre-wrap"><img src="https://lh6.googleusercontent.com/mJuf9zI6QC5w6HPVCinnLSkpp-RgufOfl7nw1E_aghDflNhusoRbZTuP_0x-RkECQRhIfvPxGMe6zSt6chyXZ7D5DdqtkZPp0q-TE8itKny8VWObWAiZ1aurYWDO0CtZgvJEXfzu" width="350" height="2" style="border:none"></span><span style="font-size:9.5pt;font-family:Arial;background-color:transparent;vertical-align:baseline;white-space:pre-wrap"><br></span></p></span></div></div></div></div></div></div></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><img src="https://lh6.googleusercontent.com/mJuf9zI6QC5w6HPVCinnLSkpp-RgufOfl7nw1E_aghDflNhusoRbZTuP_0x-RkECQRhIfvPxGMe6zSt6chyXZ7D5DdqtkZPp0q-TE8itKny8VWObWAiZ1aurYWDO0CtZgvJEXfzu" width="350" height="2" style="font-size:12.6667px;font-family:Arial;white-space:pre-wrap;border:none"></div><div dir="ltr">Jonathan D. Slavin</div><div dir="ltr">Astrophysicist - High Energy Astrophysics Division</div><div dir="ltr">Center for Astrophysics | Harvard & Smithsonian</div><div dir="ltr">Office: (617) 496-7981 | Cell: (781) 363-0035<br>60 Garden Street | MS 83 | Cambridge, MA 02138</div></div><div dir="ltr"><span><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt"><span style="font-size:9.5pt;font-family:Arial;background-color:transparent;vertical-align:baseline;white-space:pre-wrap"><img src="https://lh6.googleusercontent.com/mJuf9zI6QC5w6HPVCinnLSkpp-RgufOfl7nw1E_aghDflNhusoRbZTuP_0x-RkECQRhIfvPxGMe6zSt6chyXZ7D5DdqtkZPp0q-TE8itKny8VWObWAiZ1aurYWDO0CtZgvJEXfzu" width="350" height="2" style="border:none"></span><span style="font-size:9.5pt;font-family:Arial;background-color:transparent;vertical-align:baseline;white-space:pre-wrap"><br></span></p></span></div></div></div></div></div></div></div></div>