hold on/off for loglog axes

33 views (last 30 days)
Sarah Murphy
Sarah Murphy on 22 Nov 2023
Commented: Dyuman Joshi on 24 Nov 2023
I want to plot multiple lines on loglog axes on one figure, something like:
figure(3)
clf('reset')
hold on
loglog(t1, g1, 'r')
loglog(t2, g2, 'b')
loglog(t3, g3, 'Color', [0 .5, 0])
hold off
xlabel('$$t$$','Interpreter','latex')
ylabel('$$g$$','Interpreter','latex')
I know if I use colours that have a matlab shortcut, i.e. use 'g' for plotting g3 for example, I could plot these all in
loglog(t1, g1, 'r', t2, g2, 'b', t3, g3, 'g')
without using hold. But I've previously used the first colour scheme for my data and would like to avoid having to change all my previously saved figures.
Does anyone know a way to make the three curves different colours on loglog axes using colours that don't have a short name in Matlab?
  2 Comments
Michael
Michael on 22 Nov 2023
I am not sure if I understand your question correctly but maybe a solution could be to invoke the line 'hold on' after the first loglog.. command?
Star Strider
Star Strider on 22 Nov 2023
Does anyone know a way to make the three curves different colours on loglog axes using colours that don't have a short name in Matlab?
You can create your own colormap. See Colormap Editor for one way to create one you want. You can then use specific rows of the colormap to define specific colours.

Sign in to comment.

Accepted Answer

Dyuman Joshi
Dyuman Joshi on 22 Nov 2023
You can use colororder paired with RGB Triplets -
x = logspace(-1,2);
y1 = 10.^x;
y2 = 1./10.^x;
y3 = 1.^x;
figure
loglog(x,y1,x,y2,x,y3)
grid on
legend({'y1', 'y2', 'y3'})
figure
l = loglog(x,y1,x,y2,x,y3);
%Define RGB triplets
map = hsv(numel(l))
map = 3×3
1 0 0 0 1 0 0 0 1
%Set the colororder
colororder(map)
grid on
legend({'y1', 'y2', 'y3'})
I have used colormap to get colors. You can also define RGB triplets manually, or get random values via rand.
Additionally, if you are working with R2023b, you can use different built-in pallettes.

More Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!