0

Axis scaling in MATLAB can be either linear or logarithmic. But how can I combine both on a single axis? I'd like to scale part of my y-axis linear and part logarithmic.

The distribution function:

where I=1:.5:250; and my mu and sigma are both constant. This is the backward cumulative distribution of the function above

I plotted it using semilogx(I,(sum(f)-cumsum(f)/sum(f))), where f is the function above. Notice that the y-axis is linear.

This is the same curve but with my desired y-axis

where the y-axis is linear in [10, 90], but logarithmic in the intervals [0.01, 10] and [90, 100], resulting in a "zoom effect" in those ranges.

How can I combine linear and logarithmic scales on the same axis?

Adriaan
  • 17,741
  • 7
  • 42
  • 75
Belga10
  • 1
  • 2
  • I voted to close this question because there is no example code. Please [edit] your post to include a [minimal, complete, readable, and reproducible example](/help/minimal-reproducible-example). In other words, include the code that produced your plots. – Stephen Ostermiller Mar 09 '22 at 09:14
  • the code has nothing to do with the plot. You can plot any function you want. The point is just to how rescale the axis and adjust get the function adjusted accordingly. – Belga10 Mar 09 '22 at 09:23
  • Using other scales than linear or logarithmic cannot be done using MATLAB's axis object as far as I know. You need to either modify your data to plot as whatever you want to show it and add ticks, tick labels and grid lines where you want them to be. More hacky might be to plot different panels on different scales using `tiledlaytout()` and attempting to remove all the white space between the plots. – Adriaan Mar 09 '22 at 09:46
  • 4
    Arbitrary rescaling of an axis is an antipatern. The entire point of an axis is to have some sort of continuous understandable reference to understand the data. If you have an axis that is log, then linear then log in some arbitrary manner (as in your example), the only thing you are doing is making sure anyone reading it does not understand the data you show. Its counter productive. If you want to zoom in an area of the plot, then use other techniques, like subplots, or plots within plots, but always make sure your axis is linear in some space. – Ander Biguri Mar 09 '22 at 09:57
  • exactly I want to expand a specific area. Wih other words the y-axis is neither linear nor logarithmic. for plotting a cumulative distribution it is commun to expand those areas (from 0,90% to 10%,100% respectivly). Here is an example: doc probplot(). The problem of the probpplot function (from the Statistics and Machine Learning Toolbox ) is that this function is ment to deal with random given Data. In my case however i have a well determined distribution function. – Belga10 Mar 09 '22 at 10:07
  • 1
    Yea, so, as we said: don't do that. No-one will be able to understand your plots. Use different techniques, as @AnderBiguri mentioned, which are more appropriate. Exactly because this is uncommon and ill-advised to use, MATLAB has no option for this. If you really want to plot it as such (again: don't), you'll need to hack it together yourself. – Adriaan Mar 09 '22 at 10:24
  • @Adriaan unfortunately i have to plot it that way. I thank you for your respond. I think the only way is to try to transform the function to another one that amplified the wanted region and plot it. After that set a proper ticks. – Belga10 Mar 09 '22 at 10:36
  • 1
    You should instead do something like this: https://stackoverflow.com/questions/31246281/plot-within-a-plot-in-matlab Make a new plot inside the plot with a zoomed in version – Ander Biguri Mar 09 '22 at 10:45
  • 2
    You 'have to" sounds like a bad school project or managerial point; try to convince whomever is forcing you to do this that it's not a good idea. If you really want to do this, you can do [something like this](https://stackoverflow.com/a/65775625/5211833) or [this](https://stats.stackexchange.com/a/358706/215553) to plot three different plots (log, lin, log on the same X-scale), remove the inner axes and squeeze the rest of the whitespace out using the `position` property if necessary. – Adriaan Mar 09 '22 at 11:05
  • @AnderBiguri i thought of that but that wont help either. Because the point of the intended plot is to show on one hand how the curve behave when the y values are near the zero or the 1(100%) since it is a cumulative curve and on the other hand the entire course of the curve. This is needed for example if you compare two cumulatives functions that differ only at the beginnings or the ends. – Belga10 Mar 09 '22 at 11:08
  • 2
    Then using plots-in-plots or two subplots blown-up on the extrema, making a similar plot for the other function, would work perfectly fine. You won't transform a car into a train to compare it with another car transformed into a train either. No-one would understand that plot-type. Just use several plots instead. – Adriaan Mar 09 '22 at 11:11
  • @Adriaan it is indeed a managerial point. I will try that but it seems to be tricky and not a straight way solution. That is going to be problematic for further plots. So I think i will go with the second option which is the conviction. – Belga10 Mar 09 '22 at 11:17
  • 1
    There's another scaling which is kind-of standard, namely Gaussian scaling (not sure about the name). It resembles what you want: roughly linear in the middle, and stretched in the endpoints. See [here](https://www.mathworks.com/help/stats/normplot.html#bu1z969-2). If you want to do that, it looks like you need to apply the scaling manually (the linked function plots a pdf estimated from the provided data; you cannot provide the pdf directly). But, as others have said, using unexpected scaling will confuse the reader – Luis Mendo Mar 09 '22 at 16:28

0 Answers0