How do I plot filled markers on top of two axis

7 views (last 30 days)
I got this minimal example:
X = linspace(1,10,20);
% Create left axis
ax1=gca;
p1 = plot(X, sin(X),'MarkerFaceColor','w','Marker','s','MarkerSize',10);
% Create right axis
ax2=axes('Position',get(ax1,'Position'),'YAxisLocation','right','Color','none');hold on
p2 = plot(X,cos(X), 'Color', 'r','MarkerFaceColor','w','Marker','o','MarkerSize',10);
and get this figure:
The rectangular marker on the right side is a white filled marker and should cover the axis line like the circular one. How can I do that?
Thx,
best regards
Stefan

Answers (2)

Alan Stevens
Alan Stevens on 5 Aug 2020
Try changing the order:
X = linspace(1,10,20);
% Create axes
ax1=gca;
ax2=axes('Position',get(ax1,'Position'),'YAxisLocation','right','Color','none');hold on
p1 = plot(X, sin(X),'MarkerFaceColor','w','Marker','s','MarkerSize',10);
p2 = plot(X,cos(X), 'Color', 'r','MarkerFaceColor','w','Marker','o','MarkerSize',10);

steefan85
steefan85 on 5 Aug 2020
Okay thanks, but I guess my example was not good enough for my problem. Your solution fails with this one:
X = linspace(0,500,6);
Y1 = [1132;1241;1310;1409;1433;1452];
Y2 = [0;237;312;410;523;628]
% Create axes
ax1=gca;
ylim([0, 1500])
p1 = plot(X, Y1,'MarkerFaceColor','w','Marker','s','MarkerSize',10);
ax2=axes('Position',get(ax1,'Position'),'YAxisLocation','right','Color','none');hold on
ylim([0, 700])
p2 = plot(X, Y2, 'Color', 'r','MarkerFaceColor','w','Marker','o','MarkerSize',10);
linkaxes([ax1 ax2],'x')
Any suggestions?
  10 Comments
steefan85
steefan85 on 5 Aug 2020
I can't just plot it as pdf. I need a special font (LM Modern 10) for the axes. Eps and pdf don't do this out of Matlab, because the fonts are not embedded.
My way is to print as .svg and then export it to .pdf via Inkscape automatically.
Printing a non-vector graphic is not applicable.
Alan Stevens
Alan Stevens on 5 Aug 2020
Edited: Alan Stevens on 5 Aug 2020
Hmm. I guess the only other option is to export the data and plot it in another tool that does all you want. Apart from that, I'm out of ideas! This is a long way from your original question!

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!