Remove white border when "Copy figure"
8 次查看(过去 30 天)
显示 更早的评论
Hello, using Matlab 2016b, how can I (simply) remove the white border around my subplot group? It is a real waste if I copy a picture in an email from clipboard. Is it possible without using a complicated function from the FileExchange?
I do not have access to the image processing toolbox.
Best Regards
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/159925/image.jpeg)
2 个评论
Jan
2017-1-18
Please provide the important detail, how you "copy" the figure to the email: As screenshot? Using saveas or print? Through a command from the menu bar or programmatically?
回答(1 个)
Benjamin Kraus
2017-1-23
If you are referring to the margins surrounding your axes in the figure, the size of those margins are hard-coded within subplot, so there is no easy way to change them while still using subplot. One option you can consider is to manually create the subplot by specifying your axes position, for example:
Instead of this:
subplot(2,3,1)
plot(1:10)
subplot(2,3,2)
plot(1:10)
subplot(2,3,3)
plot(1:10)
subplot(2,3,4:6)
plot(1:10)
You can do this:
ax1 = axes('OuterPosition',[0/3 1/2 1/3 1/2]);
plot(1:10)
ax2 = axes('OuterPosition',[1/3 1/2 1/3 1/2]);
plot(1:10)
ax3 = axes('OuterPosition',[2/3 1/2 1/3 1/2]);
plot(1:10)
ax4 = axes('OuterPosition',[0/3 0/2 3/3 1/2]);
plot(1:10)
OuterPosition is specified as [left bottom width height].
The problem you will find with that approach is that the bottom axes doesn't line up with the top three. That is because the margin is in normalized units, so the wider the axes the wider the space.
There are two ways you could try to fix that:
Option 1 - Switch to non-normalized units:
ax4.OuterPosition(3) = 1/3; % Reduce the width temporarily.
ax4.Units = 'pixels'; % Switch to a non-normalized unit will "lock-in" the size of margin.
ax4.OuterPosition(3) = ax4.OuterPosition(3)*3; % Restore the width.
ax4.Units = 'normalized'; % This will allow axes to resize with figure again.
Option 2 - Set the Position of the bottom axes to match top axes.
ax4.Units = 'normalized'; % Restore the units if you tried option 1.
ax4.Position(1) = ax1.Position(1); % Align the left edge.
ax4.Position(3) = ax3.Position(1)+ax3.Position(3)-ax1.Position(1);
- Ben
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!