1

This is related to many similar questions like this one.

However the provided solutions don't really fit my needs because the tick labels then become meaningless. In my case the first y-axis is fixed and always the same. ticks from 0.0 (bottom of plot) to 1.0 with 0.2 spacing. So 6 ticks. ylim is 1.1 so there is no tick at the top of the y-axis.

What I want to plot, automatically, is cross-validation stats from a regression task. Here R2 is in range 0 to 1 (yeah could be negative but no plot needed in such cases ;) ) and mean absolute error and RMSE are in original unit size of the data which could be anything.

enter image description here

I know would like to align the second y-axis in a meaningful way which might impact it's auto-calculated ylim so that the ticks can be set nicely.

Are there any ideas how this could be done?

EDIT:

Clarification according to comment:

enter image description here

beginner_
  • 7,230
  • 18
  • 70
  • 127
  • 1
    I do have severe problems understanding the issue. Would you mind reviewing the question and [edit]ing it to clearly state what is desired and what hinders you to obtain it? – ImportanceOfBeingErnest Nov 07 '17 at 09:45
  • If you do twinx, the ticks on the y-axis are not aligned and so the plot looks bad to terrible. I want them aligned and in a way that the numbers on the tick make sense. See screenshot in question. – beginner_ Nov 07 '17 at 11:40
  • I cannot see how using the duplicate makes the labels meaningless. In this case you'd probably want `f = lambda x: x/2.+0.3` and additionally set the limits, `ax2.set_ylim(f(np.array(ax.get_ylim())))`. – ImportanceOfBeingErnest Nov 07 '17 at 14:53
  • Question: Would you present a chart with these values to management? You would not. And hence it's not a duplicate because I specifically asked to avoid the issue with using "meaningless" labels that inevitably will result by using this function approach. Also this should be automatic, if I'm going to hand-define the function I can just as well create the ticks manually. – beginner_ Nov 08 '17 at 05:34
  • Because you would not present a chart with two different scales and no indication which box belongs to which scale to management either, this is not a good argument. The labels would not be meaningless if using `f = lambda x: x/2.+0.3`; instead would mean exactly what they show. I understand that you want an automatic way to determine the label positions - this if unfortunately not possible with standard matplotlib tools if you restrict one of the axis limits to fix numbers. If you want to free this restriction, the duplicate tells you a solution. – ImportanceOfBeingErnest Nov 08 '17 at 09:19
  • If you want to ask on an algorithm to determine the ticks the way you imagine, please make that clear in the question. But then it would require to show some attempt. [This could be a good start](http://vis.stanford.edu/papers/tick-labels). – ImportanceOfBeingErnest Nov 08 '17 at 09:24

0 Answers0