Home > Mobile >  Matplotlib: how to add a ytick label (or other label that can do the job) at a given point?
Matplotlib: how to add a ytick label (or other label that can do the job) at a given point?

Time:04-06

I want to show the result of a PCC test. I have two y axes to show the r and p-value respectively. I plot a horizontal dashed line on the second axis to indicate the threshold value p=0.05 and I want to add another ytick lable (or other label as long as it's in the right location, such as the red 0.05 in the picture below) to the second y axis while keeping the original ytick labels.

According to matplotlib documentation my_plot

CodePudding user response:

You can add a text outside the plot. The twinx with extra text

Alternatively, you could set a minor tick with a label:

ax2.set_yticks([0.05], minor=True)
ax2.set_yticklabels([0.05], minor=True, color='r', fontsize=18)
  • Related