Rounded axis in plot

조회 수: 6 (최근 30일)
Leonardo
Leonardo 2023년 6월 9일
편집: DGM 2023년 6월 11일
I'm wondering if there is an option to create rounded corners for the axis. I would like to incorporate rounded axis corners in my graphics.
Thank you for your assistance.
  댓글 수: 1
Rik
Rik 2023년 6월 9일
I am not aware of this being possible. You could make the axes transparent and create several other objects to create the illusion of an axes object with rounded corners.

댓글을 달려면 로그인하십시오.

답변 (1개)

DGM
DGM 2023년 6월 11일
편집: DGM 2023년 6월 11일
Here's one terrible way:
% normalized radius of plot box corners
cornerrad = 0.1;
% we have some sort of object in the axes
% such that the object does not extend into the corners
plot(rand(1,10),rand(10,5));
% figure out rectangle position
axrange = [xlim(); ylim()];
rwidth = diff(axrange,1,2).';
% figure out rectangle curvature
cornerrad = min(cornerrad,0.5);
hax = gca;
curv = hax.PlotBoxAspectRatio([2 1])*cornerrad*2;
% create rectangle object
hfg = rectangle('position',[axrange(:,1).' rwidth],'curvature',curv,...
'facecolor','none','linewidth',0.5);
% hide the axis axles by setting the line color to white
% normally, the figure BG color is light gray, but if saved or printed, it will be white
drawnow
hax.XAxis.Axle.ColorData = im2uint8([1 1 1 1]).';
hax.YAxis.Axle.ColorData = im2uint8([1 1 1 1]).';
hax.XAxis.Axle.Layer = 'back';
hax.YAxis.Axle.Layer = 'back';
% clean up other remnants of the axes
box off
hax.Color = 'none';
% try to set up a grid
% remove the first and last yticks so that we don't have
% ticks and gridlines hanging outside the rounded corners
grid on;
yt = yticks();
yticks(yt(2:end-1))
xt = xticks();
xticks(xt(2:end-1))
This will get screwy if you try to zoom or pan, but it's a start. Note that I'm assuming that the goal is to save/print the result. I'm relying on the fact that both axes and figure background colors are white in that case. When viewed in a figure, they normally differ. Otherwise, the problem is more complicated.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by