Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
Plot multiple axes with log and linear scales
Hey guys, I need to make a plot with multiple x-axes. I've done this before without any trouble when both axes had a linear scale, and so I would use the axis command to create the second plot, and just set the xrange keyword to be whatever I needed it to be. Now however things are more complicated, because one axis is a linear scale, and the other axis is sorta kinda logarithmic scale. There is a one-to-one relationship between the axes, but the relationship is not in the least bit simple. Basically, I need a way to tell IDL, for these values on the first x-axis, plot these values for the second x-axis. Anyone know how to do this?
Re: Plot multiple axes with log and linear scales
On Wednesday, October 8, 2014 7:21:57 AM UTC-6, jens...@gmail.com wrote: > Thank you guys! After spending hours trying to xtickv myself out of this; the xtickformat strategy really is an eye-opener. > > > > I would like to add to the complexity, though: > > Suppose the function in CONV_AXIS is not a mathematical function; but instead it's data-values corresponding to the other axis? > > > > Here's my problem: > > There are three data vectors: Atmospheric temperature (T), pressure (P) and altitude (A). > > I want to plot this data such that T is on the X-axis; and both P and A are on the y-axes; where the A-axis shows the altitude-values corresponding to P. So, I don't want to calculate the A-values using the P-values as input; rather, I have to look up the corresponding values in an array, since I don't know the functional form. > > > > Furthermore, P is logarithmic while A isn't. > > > > This suggests I have to interpolate either of the y-axes onto the other; but I don't see how to, exactly. > > > > The obviously dirty way to do this is to fit the relationship between A and P (approximately exponential) to obtain a functional form; but that's not too neat... > > > > Thanks so much for any help you could offer! > > > > Jens > > > > Hi Jens, I might be misunderstanding your problem, but that "conv_axis" is an IDL function that can contain *any* code that you want. It doesn't have to be a mathematical function - it could be a lookup table, it could go out to disk and read in a file for each tick value. It doesn't matter. The only requirement is that given a specific input tick value, it needs to output the corresponding string. How you determine that string is up to you. Does that help? -Chris
On Wednesday, October 8, 2014 10:37:10 PM UTC+2, Chris Torrence wrote: > On Wednesday, October 8, 2014 7:21:57 AM UTC-6, jens...@gmail.com wrote: > >> Thank you guys! After spending hours trying to xtickv myself out of this; the xtickformat strategy really is an eye-opener. > >> > >> > >> > >> I would like to add to the complexity, though: > >> > >> Suppose the function in CONV_AXIS is not a mathematical function; but instead it's data-values corresponding to the other axis? > >> > >> > >> > >> Here's my problem: > >> > >> There are three data vectors: Atmospheric temperature (T), pressure (P) and altitude (A). > >> > >> I want to plot this data such that T is on the X-axis; and both P and A are on the y-axes; where the A-axis shows the altitude-values corresponding to P. So, I don't want to calculate the A-values using the P-values as input; rather, I have to look up the corresponding values in an array, since I don't know the functional form. > >> > >> > >> > >> Furthermore, P is logarithmic while A isn't. > >> > >> > >> > >> This suggests I have to interpolate either of the y-axes onto the other; but I don't see how to, exactly. > >> > >> > >> > >> The obviously dirty way to do this is to fit the relationship between A and P (approximately exponential) to obtain a functional form; but that's not too neat... > >> > >> > >> > >> Thanks so much for any help you could offer! > >> > >> > >> > >> Jens > >> > >> > >> > >> > > > > Hi Jens, > > > > I might be misunderstanding your problem, but that "conv_axis" is an IDL function that can contain *any* code that you want. It doesn't have to be a mathematical function - it could be a lookup table, it could go out to disk and read in a file for each tick value. It doesn't matter. The only requirement is that given a specific input tick value, it needs to output the corresponding string. How you determine that string is up to you. > > > > Does that help? > > > > -Chris Dear Chris, Thanks for your prompt response. Yes, I figured the function in conv_axis could be a lookup-table as well as a mathematical function. The problem is the interpolation. In my example: IDL will force ticks at Pressure values which do not exactly occur in the look-up table. For example; it might want to put a Pressure tick at 1000mbar; but the data only has values at 982mbar and 1012mbar; with corresponding altitudes. Therefore I would need to interpolate manually. This is especially cumbersome if I would want to have rounded altitude ticks; since now I can't do the inversion described by JD.
On Thursday, October 9, 2014 12:12:10 PM UTC+2, jens...@gmail.com wrote: > On Wednesday, October 8, 2014 10:37:10 PM UTC+2, Chris Torrence wrote: >> On Wednesday, October 8, 2014 7:21:57 AM UTC-6, jens...@gmail.com wrote: >> >>> Thank you guys! After spending hours trying to xtickv myself out of this; the xtickformat strategy really is an eye-opener. >> >>> >> >>> >> >>> >> >>> I would like to add to the complexity, though: >> >>> >> >>> Suppose the function in CONV_AXIS is not a mathematical function; but instead it's data-values corresponding to the other axis? >> >>> >> >>> >> >>> >> >>> Here's my problem: >> >>> >> >>> There are three data vectors: Atmospheric temperature (T), pressure (P) and altitude (A). >> >>> >> >>> I want to plot this data such that T is on the X-axis; and both P and A are on the y-axes; where the A-axis shows the altitude-values corresponding to P. So, I don't want to calculate the A-values using the P-values as input; rather, I have to look up the corresponding values in an array, since I don't know the functional form. >> >>> >> >>> >> >>> >> >>> Furthermore, P is logarithmic while A isn't. >> >>> >> >>> >> >>> >> >>> This suggests I have to interpolate either of the y-axes onto the other; but I don't see how to, exactly. >> >>> >> >>> >> >>> >> >>> The obviously dirty way to do this is to fit the relationship between A and P (approximately exponential) to obtain a functional form; but that's not too neat... >> >>> >> >>> >> >>> >> >>> Thanks so much for any help you could offer! >> >>> >> >>> >> >>> >> >>> Jens >> >>> >> >>> >> >>> >> >>> >> >> >> >> Hi Jens, >> >> >> >> I might be misunderstanding your problem, but that "conv_axis" is an IDL function that can contain *any* code that you want. It doesn't have to be a mathematical function - it could be a lookup table, it could go out to disk and read in a file for each tick value. It doesn't matter. The only requirement is that given a specific input tick value, it needs to output the corresponding string. How you determine that string is up to you. >> >> >> >> Does that help? >> >> >> >> -Chris > > Dear Chris, > > Thanks for your prompt response. > Yes, I figured the function in conv_axis could be a lookup-table as well as a mathematical function. The problem is the interpolation. In my example: IDL will force ticks at Pressure values which do not exactly occur in the look-up table. For example; it might want to put a Pressure tick at 1000mbar; but the data only has values at 982mbar and 1012mbar; with corresponding altitudes. Therefore I would need to interpolate manually. > > This is especially cumbersome if I would want to have rounded altitude ticks; since now I can't do the inversion described by JD. You ought to be able to pre-select which ticks values to show on the scale of the main access (e.g. pressure) so that they appear in your lookup-table. To do this, just pass (some subset) of the lookup table itself as XTICKV. Or just load the look-up table in a common block and use INTERPOL on it as needed. BTW, one thing I recently discovered about this methodology: minor tick marks do not get run through your non-linear conversion function, and so are placed in the incorrect place. This is especially subtle if you are using axes which are related non-linearly, and plotting each in log space. You might see a tick mark of 10 and an adjacent tick mark 100 with 9 minor tick marks between them, and naturally assume these will occur at the correct positions for 20, 30, 40, ... 90. But sadly they would not. The only solution I've found for this is to compute and draw these tick marks myself in the correct locations. JD