Python Forum
Cannot remove one of the x-ticks from a 2x1 subplot.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cannot remove one of the x-ticks from a 2x1 subplot.
#2
I figured out the problem. I posted my answer to Stack Exchange. Just gonna leave a copy here.

#setup second axis of plot 2
    ax22.clear()
    ln4 = ax22.plot(x2,y22,colors[1],label = 'CO2(%)')
    ax22.tick_params(axis = 'y',labelcolor = colors[1])

    #---------------------------------------------#
    #set the x-axis tick labels visibility to False
    plt.setp(ax21.get_xticklabels(),visible = False)
    #----------------------------------------------#
    
    #keep two legends from the two axes together. legends belong to an axis. In our case, we have two y-axis, so two separate legend made rather than together
    lns2 = ln3 + ln4
    labs2 = [l.get_label() for l in lns2]
    ax21.legend(lns2,labs2,bbox_to_anchor = (0,-0.1,1,0)
                # (0,1.02,1,0.102)
                ,loc = 'lower left',ncol = 3,borderaxespad = 0)
Final picture:[Image: 4DQGu.png]

What changed: added the line plt.setp(ax21.get_xticklabels(),visible = False) and change bbox_to_anchor parameters to (0,-0.1,1,0)
Reply


Messages In This Thread
RE: Cannot remove one of the x-ticks from a 2x1 subplot. - by generalzu10 - Mar-20-2024, 04:24 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to set a sequence of midi note on and note off values in ticks tomharvey 2 2,203 Mar-25-2022, 02:33 AM
Last Post: tomharvey
  Subplot - Plotting 4 plots on the same row Menthix 1 1,458 Nov-07-2021, 09:03 PM
Last Post: deanhystad
  Missing ticks on X axis drunkenneo 0 1,761 May-29-2021, 04:16 PM
Last Post: drunkenneo
  How to preserve x-axis labels despite deleted subplot? Mark17 1 1,967 Dec-23-2020, 09:02 PM
Last Post: Mark17
  create loop of subplot plotly dash without hardcode tonycat 0 3,950 Sep-23-2020, 08:40 AM
Last Post: tonycat
  python ticks programmer229193 2 2,200 May-07-2020, 04:21 AM
Last Post: programmer229193
  Matplotlib Colorbar Ticks (Increase number) BennyS 1 8,880 Apr-18-2018, 04:00 PM
Last Post: BennyS

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020