Remove all markers from line plot using second yaxis

27 次查看(过去 30 天)
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 All of those markers and different line styles need to be simple and plain lines.
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.)

回答(2 个)

Greg Peacock
Greg Peacock 2020-8-6
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');

Takumi
Takumi 2019-3-19
Try this at the end of your program.
obj = findobj(gca,'type','line');
set(obj,'LineStyle','-');
  2 个评论
Cg Gc
Cg Gc 2019-3-19
编辑:Cg Gc 2019-3-20
That didn't do anything at all. I even tried after every single line of "plot" and still there were markers and different types of lines.
Cg Gc
Cg Gc 2019-3-22
I don't know what is going on, but I have come up with an error code at least. I generated two sets of double values. One is a date, the other is just a long column of values.
The first code generates a plot, but the markers are present.
The second does not plot anything and has an error code.
Please explain and help.
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(ABNAWSversion3S2DecimalDate(1:2000,1),ABNAWSversion3S2Data(1:2000,5),'LineWidth',1,'Color',[0 0 0]); hold on; %These are on the first axis.
plot(ABNAWSversion3S2DecimalDate(1:2000,1),ABNAWSversion3S2Data(1:2000,6),'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(ABNAWSversion3S2DecimalDate(1:2000,1),ABNAWSversion3S2Data(1:2000,7),'LineWidth',1,'Color',[0.749 0 0.749]); hold on; %These go on the second axis
plot(ABNAWSversion3S2DecimalDate(1:2000,1),ABNAWSversion3S2Data(1:2000,9),'LineWidth',1,'Color',[0.749 0 0.749]);
>> 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(ABNAWSversion3S2DecimalDate(1:2000,1),ABNAWSversion3S2Data(1:2000,5),'LineWidth',1,'Color',[0 0 0]); hold on; %These are on the first axis.
plot(ABNAWSversion3S2DecimalDate(1:2000,1),ABNAWSversion3S2Data(1:2000,6),'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(ABNAWSversion3S2DecimalDate(1:2000,1),ABNAWSversion3S2Data(1:2000,7),'LineWidth',1,'Color',[0.749 0 0.749],'-'); hold on; %These go on the second axis
plot(ABNAWSversion3S2DecimalDate(1:2000,1),ABNAWSversion3S2Data(1:2000,9),'LineWidth',1,'Color',[0.749 1 0.749],'-');
Error using plot
Data must be a single matrix Y or a list of pairs X,Y.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by