Showing only part of markers that overflow off the edges of a plot?

22 Ansichten (letzte 30 Tage)
Shilpa Raja
Shilpa Raja am 20 Apr. 2016
Kommentiert: Shai Asher am 15 Jan. 2024
Hi, I am trying to make a graph look nice by increasing the size of the markers. At the size of marker that looks the best, the marker actually flows off the graph and covers the numbers. In origin and other softwares, you can set it so it only shows the part of the marker on the edge that does not extend outside the edge. Is there a way to do this in MATLAB (I.e., if a marker flows off the edge of a plot window, tell MATLAB to only display half the marker or the part within the plot window)? In the abovementioned other softwares you can also set markers to have a 3D look or gradient color. Is it possible to do this in MATLAB?

Antworten (2)

Mike Garrity
Mike Garrity am 20 Apr. 2016
No there isn't a simple way to do that type of clipping with markers. In fact, you wouldn't believe how much work we do to get markers to do anchor point clipping.
If you really need this (and the 3d or gradient look), then your best bet would probably be to write a function that made markers out of "regular" geometry. Here's a really simple example:
function my_markers(x,y,w)
[sx,sy,sz] = sphere;
z = zeros(size(x));
npts = size(x,1);
for i=1:npts
surface(x(i)+sx*w/2,y(i)+sy*w/2,z(i)+sz*w/2, ...
'FaceColor',[.929 .694 .125],'EdgeColor','none', ...
'FaceLighting','gouraud')
end
I can use that function like this:
my_markers(randn(100,1),randn(100,1),.5)
xlim([-2 2])
ylim([-2 2])
axis equal
camlight
%

Alexander Weitzel
Alexander Weitzel am 7 Nov. 2022
Even though this question is already quite old, I can present a simple and viable solution for the problem of overflowing markers.
Assuming you are interested in a clean picture for an article or a dissertation, simply set 'ClippingStyle' to 'rectangle' and print the figure to pdf, parts of markers lying outside of axes are now clipped.
set(gca,'ClippingStyle','rectangle');
print(gcf,'foo.pdf','-dpdf','-r300','-bestfit');
  1 Kommentar
Shai Asher
Shai Asher am 15 Jan. 2024
hi,
I have a similar problem with a 'fill' object. It spills over only when the figure is printed to a file (see attached).
the solution that you suggested doesn't seem to solve the matter in this case.
any other suggestions?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by