python - Turn off the the upper/right axis tick marks -


I want to tick on the invisible right and upper axis and I'm not sure what the third line should be:

  as matplotlib.pyplot plt plt.plot (x, y) #plt.upper_right_axis_ticks_off ()    

) Using ax.xaxis.set_ticks_position and ax.yaxis.set_ticks_position methods.

If you If you want to set the axis to invisible, see the class. You just need to set the color of the fork using ax.spines [spine] .set_color method none .

If you do not want to change the spindle, and manually change the plots to display a lot, there is a function below which will work for you. . Basically, you define for each axis that you want the color (in this case any will not provide it invisible), and ticks marks for all axes of the function invisible also "closed" I will also add textlines and fontsus between the ticklables and pad along with the option to define the linewidth of the latitude lines. . DefCastexis (ax, c_left = 'k', c_bottom = 'k', c_right = 'none', c_top = 'none', lw = 3, size = 12, pad = 8 ): For c_span, zip in the spinal cord ([c_left, c_bottom, c_right, c_top], ['left', 'bottom', 'right', 'top']): If c_spine! = 'None' Spin] [spin]. Sitgolar ax. [Spine]. Set_lineWidth (LW) Other: AX [Spine] .set_color ('none') if (c_bottom == 'none') & amp; (C_top == 'none'): # Any other top ax.xaxis.set_ticks_position below ('none') elif (c_bottom! = 'None') & amp; (C_top! = 'None'): # ax.tick_params (axis = 'x', direction = 'out', width = lw, length = 7, color = c_bottom, labelsize = size, pad = pad) elif (C_bottom! = 'None') & amp; (C_top == 'none'): # but top ax.xaxis.set_ticks_position ('bottom') ax.tick_params (axis = 'x', direction = 'out', width = lw, length = 7, color = c_bottom , Label = size, pad = pad) alif (c_bottom == 'none') & amp; (C_top! = 'None'): # But top ax.xaxis.set_ticks_position ('top') ax.tick_params (axis = 'x', direction = 'out', width = lw, length = 7, color = c_top , Labels = size, pad = pad) if (c_left == 'none') & amp; (C_right == 'none'): # No left and no right ax.yaxis.set_ticks_position ('none') elif (c_left! = 'None') & amp; (C_right! = 'None'): Left and right ax.tick_params (axis = 'y', direction = 'out', width = lw, length = 7, color = c_ left, label = size, pad = pad) Elif (C_left! = 'None') & amp; (C_right == 'none'): # left but not right ax.yaxis.set_ticks_position ('left') ax.tick_params (axis = 'y', direction = 'out', width = lw, length = 7, color = C_left, label = size, pad = pad) Eleph (c_left == 'none') & amp; (C_right! = 'None'): # No left but right ax.yaxis.set_ticks_position ('right') ax.tick_params (axis = 'y', direction = 'out', width = lw, length = 7, color = C_right, labelsize = size, pad = pad)

Below is an example of using it:

  Import nppy as import matplotlib.pyplot Plt fig for ax ([ax1, ax2], [ax3, ax4]) = plt.subplots (nrows = 2, ncols = 2) in axis in [Ax1, ax2, ax3, ax4]: ax.plot (np) .random Randon (10), LW = 2) Customsis (Axis 1) #default: No rights and top axis custom consultancy (A2, C_ byte = ' Custom (Ax3, c_left = 'none', c_bottom = 'k', c_right = 'k', c_top = 'none', 'none', c_bottom = 'none', c_write = 'k', 'c'top ​​= '); 



Comments