Issue with plotting order
Hello,
I have been trying to plot a shaded area (right y-axis) behind two lines (left y-axis), as shown in the code below. However, the shaded area always appears last, covering up the two lines. I’ve done this kind of graph before but have never had this issue. Best I can tell, it is because the right y-axis is plotted last. Is there a way to make the right y-axis plotted first? I can’t simply switch which data is on the axis, unfortunately: they need to be in this order. Thanks for any help!
clear; clc; close all;
Data = xlsread("FigureOfMeritResults.xlsx");
% Extract data
Date = Data(469:1908,1);
FoM = Data(469:1908,3);
GHI = Data(469:1908,4);
% Calculate the running average over 5 data points
FoM_avg = movmean(FoM, 5);
GHI_avg = movmean(GHI, 5);
dFoM = zeros(length(FoM),1) + mean(FoM);
ticks = {’12:00AM’,’4:00AM’,’8:00AM’,’12:00PM’,’4:00PM’,’8:00PM’,’12:00AM’};
fz = 15;
%%
fig = figure;
set(gcf,’Color’,’w’,’Units’,’inches’)
set(gcf,’Position’,[1,1,5,6])
GHI_color = [0.8 0.8 1];
yyaxis left;
p1 = scatter(Date, FoM, ‘Marker’, ‘.’, ‘SizeData’, 15, ‘MarkerFaceColor’, "#0072BD");
hold on;
p2 = scatter(Date, dFoM, ‘Marker’, ‘_’, ‘SizeData’, 15, ‘MarkerFaceColor’, ‘black’);
hold on;
ax = gca;
ax.YColor = ‘k’;
yyaxis right;
xData = [Date; flipud(Date)];
yData = [zeros(size(GHI)); flipud(GHI)];
fillHandle = fill(xData, yData, GHI_color,’EdgeColor’,’none’);
hold on;
ax = gca;
ax.YColor = ‘k’;
xlabel(‘Time of Day (hrs)’, ‘FontSize’, fz);
numTicks = length(ticks);
tickPositions = linspace(min(Date), max(Date), numTicks);
xticks(tickPositions);
xticklabels(ticks);
set(gca, ‘FontSize’, fz);
ax = gca;
box on;
set(ax,’BoxStyle’,’full’,’LineWidth’,2,’XGrid’,’off’,’XMinorTick’,’off’,’YGrid’,’off’,…
‘YMinorTick’,’on’);Hello,
I have been trying to plot a shaded area (right y-axis) behind two lines (left y-axis), as shown in the code below. However, the shaded area always appears last, covering up the two lines. I’ve done this kind of graph before but have never had this issue. Best I can tell, it is because the right y-axis is plotted last. Is there a way to make the right y-axis plotted first? I can’t simply switch which data is on the axis, unfortunately: they need to be in this order. Thanks for any help!
clear; clc; close all;
Data = xlsread("FigureOfMeritResults.xlsx");
% Extract data
Date = Data(469:1908,1);
FoM = Data(469:1908,3);
GHI = Data(469:1908,4);
% Calculate the running average over 5 data points
FoM_avg = movmean(FoM, 5);
GHI_avg = movmean(GHI, 5);
dFoM = zeros(length(FoM),1) + mean(FoM);
ticks = {’12:00AM’,’4:00AM’,’8:00AM’,’12:00PM’,’4:00PM’,’8:00PM’,’12:00AM’};
fz = 15;
%%
fig = figure;
set(gcf,’Color’,’w’,’Units’,’inches’)
set(gcf,’Position’,[1,1,5,6])
GHI_color = [0.8 0.8 1];
yyaxis left;
p1 = scatter(Date, FoM, ‘Marker’, ‘.’, ‘SizeData’, 15, ‘MarkerFaceColor’, "#0072BD");
hold on;
p2 = scatter(Date, dFoM, ‘Marker’, ‘_’, ‘SizeData’, 15, ‘MarkerFaceColor’, ‘black’);
hold on;
ax = gca;
ax.YColor = ‘k’;
yyaxis right;
xData = [Date; flipud(Date)];
yData = [zeros(size(GHI)); flipud(GHI)];
fillHandle = fill(xData, yData, GHI_color,’EdgeColor’,’none’);
hold on;
ax = gca;
ax.YColor = ‘k’;
xlabel(‘Time of Day (hrs)’, ‘FontSize’, fz);
numTicks = length(ticks);
tickPositions = linspace(min(Date), max(Date), numTicks);
xticks(tickPositions);
xticklabels(ticks);
set(gca, ‘FontSize’, fz);
ax = gca;
box on;
set(ax,’BoxStyle’,’full’,’LineWidth’,2,’XGrid’,’off’,’XMinorTick’,’off’,’YGrid’,’off’,…
‘YMinorTick’,’on’); Hello,
I have been trying to plot a shaded area (right y-axis) behind two lines (left y-axis), as shown in the code below. However, the shaded area always appears last, covering up the two lines. I’ve done this kind of graph before but have never had this issue. Best I can tell, it is because the right y-axis is plotted last. Is there a way to make the right y-axis plotted first? I can’t simply switch which data is on the axis, unfortunately: they need to be in this order. Thanks for any help!
clear; clc; close all;
Data = xlsread("FigureOfMeritResults.xlsx");
% Extract data
Date = Data(469:1908,1);
FoM = Data(469:1908,3);
GHI = Data(469:1908,4);
% Calculate the running average over 5 data points
FoM_avg = movmean(FoM, 5);
GHI_avg = movmean(GHI, 5);
dFoM = zeros(length(FoM),1) + mean(FoM);
ticks = {’12:00AM’,’4:00AM’,’8:00AM’,’12:00PM’,’4:00PM’,’8:00PM’,’12:00AM’};
fz = 15;
%%
fig = figure;
set(gcf,’Color’,’w’,’Units’,’inches’)
set(gcf,’Position’,[1,1,5,6])
GHI_color = [0.8 0.8 1];
yyaxis left;
p1 = scatter(Date, FoM, ‘Marker’, ‘.’, ‘SizeData’, 15, ‘MarkerFaceColor’, "#0072BD");
hold on;
p2 = scatter(Date, dFoM, ‘Marker’, ‘_’, ‘SizeData’, 15, ‘MarkerFaceColor’, ‘black’);
hold on;
ax = gca;
ax.YColor = ‘k’;
yyaxis right;
xData = [Date; flipud(Date)];
yData = [zeros(size(GHI)); flipud(GHI)];
fillHandle = fill(xData, yData, GHI_color,’EdgeColor’,’none’);
hold on;
ax = gca;
ax.YColor = ‘k’;
xlabel(‘Time of Day (hrs)’, ‘FontSize’, fz);
numTicks = length(ticks);
tickPositions = linspace(min(Date), max(Date), numTicks);
xticks(tickPositions);
xticklabels(ticks);
set(gca, ‘FontSize’, fz);
ax = gca;
box on;
set(ax,’BoxStyle’,’full’,’LineWidth’,2,’XGrid’,’off’,’XMinorTick’,’off’,’YGrid’,’off’,…
‘YMinorTick’,’on’); plot, area MATLAB Answers — New Questions