Legend colors change when I have two y axes
Hi,
I am having difficulties with making figure. Here is the thing:
I have 10 different data sets. 2nd starts at the timestamp 1st end etc. Each data sets are saved and have similarly named variablses. I want data "density" to be on the left y axis and 7 measurements to be on the right y axis. The problem is with legend. After 1st measurement everything is ok. But when I run code again with another dataset, legend colors and linestyle will change. I’ll add both code and pictures of legends in several times.
Legend after 1st measurement. This is how it should look like:
And after 2 runs:
after many runs:
The program is using whole different legends.
So, here is the code. (before I had 8 measurements, but now I only need 7)
colors=["#028A0F","#1D57A9","#3DCBC8","#9C58A1","#F0D04D","#CD0027","#EF9F26","#B2B3B5","#FA9DAC","#98FF98","#67032F","#010101"];
fig1=figure(1);
hold on
yyaxis left
plot(Time_h,density, ‘color’, ‘#000000′,’LineStyle’,’:’);
axLeft=gca;
axLeft.YColor = "#000000";
axLeft.XLim=[0,350];
axLeft.YLim=[0,1.5];
ylabel(‘density’);
yyaxis right
plot(Time_h,Measure_1, ‘color’, colors(1),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_2, ‘color’, colors(2),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_3, ‘color’, colors(3),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_4, ‘color’, colors(4),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_5, ‘color’, colors(5),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_6, ‘color’, colors(6),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_7, ‘color’, colors(7),’LineStyle’,’-‘,’Marker’,’none’);
ylabel(”)
axRight=gca;
axRight.YLim=[0,1];
axRight.YColor = "#000000";
lgnd=legend(‘density’,’Measurement 1′,’Measurement 2′,’Measurement 3′,’Measurement 4′,’Measurement 5′,’Measurement 6′,’Measurement 7′);
xlabel(‘Time_ (h)’);
I upload always the data and then run the code and then repeat. I don’t close the picture between these. The final picture is then saved.
So thanks in advance and I can describe problem more if nessessary.Hi,
I am having difficulties with making figure. Here is the thing:
I have 10 different data sets. 2nd starts at the timestamp 1st end etc. Each data sets are saved and have similarly named variablses. I want data "density" to be on the left y axis and 7 measurements to be on the right y axis. The problem is with legend. After 1st measurement everything is ok. But when I run code again with another dataset, legend colors and linestyle will change. I’ll add both code and pictures of legends in several times.
Legend after 1st measurement. This is how it should look like:
And after 2 runs:
after many runs:
The program is using whole different legends.
So, here is the code. (before I had 8 measurements, but now I only need 7)
colors=["#028A0F","#1D57A9","#3DCBC8","#9C58A1","#F0D04D","#CD0027","#EF9F26","#B2B3B5","#FA9DAC","#98FF98","#67032F","#010101"];
fig1=figure(1);
hold on
yyaxis left
plot(Time_h,density, ‘color’, ‘#000000′,’LineStyle’,’:’);
axLeft=gca;
axLeft.YColor = "#000000";
axLeft.XLim=[0,350];
axLeft.YLim=[0,1.5];
ylabel(‘density’);
yyaxis right
plot(Time_h,Measure_1, ‘color’, colors(1),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_2, ‘color’, colors(2),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_3, ‘color’, colors(3),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_4, ‘color’, colors(4),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_5, ‘color’, colors(5),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_6, ‘color’, colors(6),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_7, ‘color’, colors(7),’LineStyle’,’-‘,’Marker’,’none’);
ylabel(”)
axRight=gca;
axRight.YLim=[0,1];
axRight.YColor = "#000000";
lgnd=legend(‘density’,’Measurement 1′,’Measurement 2′,’Measurement 3′,’Measurement 4′,’Measurement 5′,’Measurement 6′,’Measurement 7′);
xlabel(‘Time_ (h)’);
I upload always the data and then run the code and then repeat. I don’t close the picture between these. The final picture is then saved.
So thanks in advance and I can describe problem more if nessessary. Hi,
I am having difficulties with making figure. Here is the thing:
I have 10 different data sets. 2nd starts at the timestamp 1st end etc. Each data sets are saved and have similarly named variablses. I want data "density" to be on the left y axis and 7 measurements to be on the right y axis. The problem is with legend. After 1st measurement everything is ok. But when I run code again with another dataset, legend colors and linestyle will change. I’ll add both code and pictures of legends in several times.
Legend after 1st measurement. This is how it should look like:
And after 2 runs:
after many runs:
The program is using whole different legends.
So, here is the code. (before I had 8 measurements, but now I only need 7)
colors=["#028A0F","#1D57A9","#3DCBC8","#9C58A1","#F0D04D","#CD0027","#EF9F26","#B2B3B5","#FA9DAC","#98FF98","#67032F","#010101"];
fig1=figure(1);
hold on
yyaxis left
plot(Time_h,density, ‘color’, ‘#000000′,’LineStyle’,’:’);
axLeft=gca;
axLeft.YColor = "#000000";
axLeft.XLim=[0,350];
axLeft.YLim=[0,1.5];
ylabel(‘density’);
yyaxis right
plot(Time_h,Measure_1, ‘color’, colors(1),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_2, ‘color’, colors(2),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_3, ‘color’, colors(3),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_4, ‘color’, colors(4),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_5, ‘color’, colors(5),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_6, ‘color’, colors(6),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_7, ‘color’, colors(7),’LineStyle’,’-‘,’Marker’,’none’);
ylabel(”)
axRight=gca;
axRight.YLim=[0,1];
axRight.YColor = "#000000";
lgnd=legend(‘density’,’Measurement 1′,’Measurement 2′,’Measurement 3′,’Measurement 4′,’Measurement 5′,’Measurement 6′,’Measurement 7′);
xlabel(‘Time_ (h)’);
I upload always the data and then run the code and then repeat. I don’t close the picture between these. The final picture is then saved.
So thanks in advance and I can describe problem more if nessessary. legend, yyaxis, colors, colororder MATLAB Answers — New Questions