I know this question seems similar to a lot of other questions here, but I've tried them and unfortunately none of them are addressing the problem I'm currently facing when trying to add a secondary y-axis.
The problem is quite simple, but I can't find anything that would fix it: Adding a secondary y-axis on my SkewT plot changes the y-limits of the plot instead of just adding the axis.
Basically, I wish to add a secondary y-axis since the height is presented using pressure levels inside a SkewT, but it should also be possible to show that height in km as well. I want to tell the second y-axis that:
- It should scale between 1015 and 100hPa (just like the original y-axis);
- I want to show only 0, 1, 3, 6, 9, 12, 15 km on the secondary y-axis (simple pressure (hPa) to height (km) conversion);
- I want the 0km to start on the first pressure level and scale from there;
- The secondary y-axis should also use log scaling in Y.
Here's an example of what it looks like with the secondary axis, you can see that the scaling if off compared to the first axis:
Here's the bit of code I added to get the change, although just adding the first line changes the graph:
twin = skew.ax.twinx()
twin.set_yscale('log')
twin.spines['right'].set_position(('axes', 0))
twin.set_frame_on(True)
twin.patch.set_visible(False)
twin.set_ylim(skew.ax.get_ylim())
Here is a simpler example so you can test it out yourselves using Metpy's Simple Sounding code example found
Since this is assuming a standard atmosphere, the 0km tick corresponds exactly to the 1013.25 mb level.