Rounded axis in plot
6 ビュー (過去 30 日間)
古いコメントを表示
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
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
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Graphics Performance についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
