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