1

I'm using the ax2 = ax1.twinx() attribute to have several graphs(3) with different scaling in the same plot, unfortunately, the values of the y-axis "run on top of each other" as shown here (right y axis, the blue values are sometimes hidden)
enter image description here


Here is the code for the graphs for reference

fig, ax1 = plt.subplots()
mpl.rcParams['lines.linewidth'] = 0.4

SMOOTH_FAC = 0.85

color = 'tab:red'
ax1.set_xlabel('Iterations')
ax1.set_ylabel('Non metric loss', color=color)
ax1.plot(smooth(net_loss,SMOOTH_FAC), color=color)
ax1.tick_params(axis='y', labelcolor=color)


ax2 = ax1.twinx()  # instantiate a second axes that shares the same x-axis
color = 'tab:blue'
ax2.set_ylabel('Metric supervised loss', color=color)  # we already handled the x-label with ax1
ax2.plot(smooth(metric_super_loss,SMOOTH_FAC), color=color)
ax2.tick_params(axis='y', labelcolor=color)


ax3 = ax1.twinx()
color = 'tab:orange'
ax3.set_ylabel('Supervised loss', color=color,labelpad=20)  # we already handled the x-label with ax1
ax3.plot(smooth(supervised_loss,SMOOTH_FAC),color=color, zorder=1)
ax3.tick_params(axis='y', labelcolor=color)

ax1.set_zorder(ax2.get_zorder()+ax3.get_zorder()+1)
ax1.patch.set_visible(False)
fig.tight_layout() 
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
DsCpp
  • 2,259
  • 3
  • 18
  • 46

1 Answers1

2

you can use get_yaxis().set_ticks() for each axes and set the tick to a blank list []

ax1.get_yaxis().set_ticks([])
ax2.get_yaxis().set_ticks([])
ax2.get_yaxis().set_ticks([])

or you can use the set_yticklabels() function to set tick for each axes.

ax1.set_yticklabels([])
ax2.set_yticklabels([])
ax3.set_yticklabels([])

or you can add left=False, right=False, labelleft=False, labelright=False params to your tick_params() for each axes

ax1.tick_params(axis='y', labelcolor=color,left=False, right=False,labelleft=False, labelright=False)

first one is cleaner.

Shijith
  • 4,602
  • 2
  • 20
  • 34
  • It made the ticks to disappear, I just want them to be One after the other, or with an offset, like the `labelpad` parameter – DsCpp Oct 10 '19 at 09:10