Single line plot with fixed axis

Dear Matlab helper,
I wonder if there is any easy way to make the following plot with matlab? It is na line plot with fixed x and y axis. x axis need to be scientific and logarithmic scale. The line has intervals as well (Y1 and Y2). I was trying with fixing the axis scales but not anywhere close to make it ^_^; Please see the attached figure to see what i wanted to make!
For axis scale i used the following code but it is as i mentioned far from the figure.
x=0.00000008:0.00000001:0.00000003;
y=0:50:300
bar(0.00000045, 200)

 Risposta accettata

Rik
Rik il 24 Feb 2021
Every axes object has an XScale property you can set to 'log' to get the desired plot. You can use the normal plotting tools (e.g. plot and errorbar) after or before setting that. You can simply use
set(gca,'XScale','log')

6 Commenti

Harr
Harr il 24 Feb 2021
Thank you very much Rik!
But how to plot the line with two section on the same x coordinate (as shown in the figure)? With the normal plotting tools it ask for a data set but i wanted to set the data manually instead because i dont have a standard data set and the error bar has its own x and y-range. Any further suggestions for a novis in MATLAB ^_^?
Best regards
/Hedi
Rik
Rik il 24 Feb 2021
The plot function allows you to specify x and y coordinates. You can't color parts of the line with the different colors (you actually can, but it is a bit tricky). The easiest is to plot the two sections separately. Don't forget to use hold(gca,'on') after the first plot.
If you are so new to Matlab that you don't know how to find the documentation yet, I would strongly suggest doing a crash course in Matlab. There are many tutorials you could follow, I recommend doing the Onramp tutorial (which is provided for free by Mathworks).
Harr
Harr il 24 Feb 2021
Thank you very much Rik, I already started Onramp tutorial. I am also curious to learn and communicate with experts.
Harr
Harr il 17 Mar 2021
Modificato: Harr il 17 Mar 2021
Hi again,
I think i am progressing in making the plot. I wonder how to put labels outside the x-axis? I got the attached plot using the code shown below:
ax = gca; % current axes
ax.FontSize = 12;
ax.TickDir = 'out';
ax.TickLength = [0.02 0.06];
set(gca,'XAxisLocation','top','YAxisLocation','left','ydir','reverse','XScale','log');
SecUp = 12;
SecLow = 200;
T = 0.00000006;
hold(gca,'on')
plot([T; T], [SecUp; SecLow], 'LineWidth',3)
ax.YLim = [0 250];
ax.XLim = [1E-8 1E-3];
xticklabels({'1E-8','1E-7','1E-6','1E-5','1E-4','1E-3'})
ax.YDir= 'reverse';
% ax.XDir= 'reverse';
grid minor
xlabel("T (m^2/s)")
ylabel("Lengh along BH (m)")
title("HFM01")
hold(gca,'on')
SecUp = 0;
SecLow = 12;
T = 0.00000006;
hold(gca,'on')
plot([T; T], [SecUp; SecLow], 'LineWidth',5)
hold(gca,'on')
SecUp = 50;
SecLow = 150;
T = 0.00000007;
hold(gca,'on')
plot([T; T], [SecUp; SecLow], 'LineWidth',3)
Rik
Rik il 17 Mar 2021
I formatted your code for you (which you can do yourself) and ran it (which you probably currently can't). As you can see, there is no issue on R2021a. Which release are you using?
Harr
Harr il 17 Mar 2021
Hi Rik,
I am using 2018b.

Accedi per commentare.

Più risposte (0)

Prodotti

Richiesto:

il 24 Feb 2021

Commentato:

il 17 Mar 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by