Remove all markers from line plot using second yaxis
15 views (last 30 days)
Show older comments
Hello everyone,
I think I have tried everything to fix this, but I am stumped. I am trying to plot 2 "line" plots over each other. The plot connected to the left yaxis is fine, but when I add the second axis two things go all wonky.
1) Markers and line style... no matter what I try, the markers on the 2nd yaxis plots stay. I have tried to change them using, '-', '.', and 'none'. I would like to have them all gone. No markers at all and have all of the line styles be the same.
2)The plot for the first yaxis moves to a weird place in the graph. This only happens everyone once in a while, usually when I try to change the appearance of the second yaxis.
Basically, I want to plot 2 groups of information over each other. I've even tried switch the data associated with each axis and the markers still show up. How do I set the markers to 'non' and the line style to '-'?
figure('Color','w','units','normalized','outerposition',[0 0 1 1])%Colors the figure white.
box off;
h = gca;
h.XAxis.LineWidth = 2;
h.YAxis(1).LineWidth = 2;
h.YAxis(1).FontWeight = 'bold';
h.XAxis.FontWeight = 'bold';
h.YAxis(1).Color = [0 0 0];
xlabel('Year','FontName','Times New Roman','fontweight','bold','FontSize',16)
ylabel('Snowfall accumulation (mm we)','FontName','Times New Roman','fontweight','bold','FontSize',16)
hold on;
plot(DecDate1,a1980,'LineWidth',1,'Color',[0 0 0]); hold on; %These are on the first axis.
plot(DecDate2,a1981,'LineWidth',1,'Color',[0 1 0]); hold on;
h = gca;
yyaxis right;
h.YAxis(2).LineWidth = 2;
h.YAxis(2).FontWeight = 'bold';
h.YAxis(2).Color = [.740 0 .749];
ylabel('Degrees (°C)','FontName','Times New Roman','fontweight','bold','FontSize',16)
hold on;
plot(Jan6hrLYdecdate,Jan1980,'LineWidth',1,'Color',[0.749 0 0.749]); hold on; %These go on the second axis
plot(Feb6hrLYdecdate,Feb1980,'LineWidth',1,'Color',[0.749 0 0.749]);
plot(Mar6hrLYdecdate,Mar1980,'LineWidth',1,'Color',[0.749 0 0.749]);
plot(Apr6hrLYdecdate,Apr1980,'LineWidth',1,'Color',[0.749 0 0.749]);
plot(May6hrLYdecdate,May1980,'LineWidth',1,'Color',[0.749 0 0.749]);
plot(Jun6hrLYdecdate,Jun1980,'LineWidth',1,'Color',[0.749 0 0.749]);
plot(Jul6hrLYdecdate,Jul1980,'LineWidth',1,'Color',[0.749 0 0.749]);
plot(Aug6hrLYdecdate,Aug1980,'LineWidth',1,'Color',[0.749 0 0.749]);
plot(Sept6hrLYdecdate,Sept1980,'LineWidth',1,'Color',[0.749 0 0.749]);
plot(Oct6hrLYdecdate,Oct1980,'LineWidth',1,'Color',[0.749 0 0.749]);
plot(Nov6hrLYdecdate,Nov1980,'LineWidth',1,'Color',[0.749 0 0.749]);
plot(Dec6hrLYdecdate,Dec1980,'LineWidth',1,'Color',[0.749 0 0.749]); hold on;
Using this code, this is what I get.
![Capture2019.JPG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/209174/Capture2019.jpeg)
All decdate variables are simply the dates the samples were collected, listed as a decimal. "a1980" and "Jan1980", etc are the sample readings. There are several hundred samples per month and per year.
(Sorry about the colors. I just thought it would make it easier to distinguish the styles.)
0 Comments
Answers (2)
Greg Peacock
on 6 Aug 2020
Late to the question, but you could try this. Make sure you include it in your "yyaxis right" section.
yyaxis right
obj = findobj(gca,'type','line');
set(obj,'LineStyle','-');
set(obj,'Marker','none');
0 Comments
Takumi
on 19 Mar 2019
Try this at the end of your program.
obj = findobj(gca,'type','line');
set(obj,'LineStyle','-');
2 Comments
See Also
Categories
Find more on Line Plots 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!