Rounded axis in plot
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Rik
le 9 Juin 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.
Réponses (1)
DGM
le 11 Juin 2023
Modifié(e) : DGM
le 11 Juin 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.
0 commentaires
Voir également
Catégories
En savoir plus sur Graphics Performance dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
