Rounded axis in plot

6 visualizzazioni (ultimi 30 giorni)
Leonardo
Leonardo il 9 Giu 2023
Modificato: DGM il 11 Giu 2023
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 Commento
Rik
Rik il 9 Giu 2023
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.

Accedi per commentare.

Risposte (1)

DGM
DGM il 11 Giu 2023
Modificato: DGM il 11 Giu 2023
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.

Categorie

Scopri di più su Graphics Performance in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by