Why colororder function does not work with ylim?
Show older comments
Hello everybody,
I have a problem with my Matlab code. I would like to make a 2D plot with two y-axis with different axis limits. The created a proper function for the colors and I used them using the colororder function. However, it does not work with I wrote ylim function.
Do you know why?
I hope you can help me :)
Here my code:
figure
hold on
fontsize(12,"points");
x=[0,6,24,48,72];
xlabel('Time [h]');
yyaxis left
ylabel('Sugars [g/L]');
Glu1=[20.68,23.35,5.41,0.54,0];
errGlu1=[0.77,2.07,0.69,0.12,0];
Fru1=[5.19,5.55,2.07,0.93,0.78];
ylim([0 25])
yyaxis right
ylabel('Products [g/L]');
Et1=[0,0.16,7.51,9.37,8.20];
errEt1=[0,0.02,0.34,0.71,0.42];
Gly1=[0,0.2,0.3,0.36,0.37];
errGly1=[0,0.01,0.03,0.03,0.04];
ylim([0 12]);
plot(x,Glu1,'^-','LineWidth',2);
plot(x,Fru1,'^-','LineWidth',2);
plot(x,Et1,'v-', 'LineWidth',2);
plot(x,Gly1,'v-','LineWidth',2);
errorbar(x,Glu1,errGlu1,'LineStyle','none','Color','black');
errorbar(x,Fru1,errFru1,'LineStyle','none','Color','black');
errorbar(x,Et1,errEt1,'LineStyle','none','Color','black');
errorbar(x,Gly1,errGly1,'LineStyle','none','Color','black');
newcolors = [0.83 0.14 0.14
1.00 0.54 0.00
0.47 0.25 0.80
0.25 0.80 0.54];
colororder(newcolors)
hold off
4 Comments
Dyuman Joshi
on 9 Oct 2023
There is an undefined variable in your code, see above.
Also, specify which plots you want to draw with the left y-axis and which ones with the right y-axis.
Ludovica Varriale
on 9 Oct 2023
Dyuman Joshi
on 9 Oct 2023
Do you want to colors the individual plots according to the newcolors array?
If not, please specify the output that you want to obtain.
Ludovica Varriale
on 9 Oct 2023
Accepted Answer
More Answers (0)
Categories
Find more on Errorbars in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


