- For the export, if you use the newer exportgraphics instead of print, it'll just do this. This is maybe the best thing about exportgraphics compared to print/saveas!
- For the figure window, you can get rid of most of the whitespace by using tiledlayout and nexttile (with a 1x1 layout) setting the Padding property to tight. It doesn't get rid of all of the whitespace but the majority of it.
Remove whitespace right to colorbar
조회 수: 8 (최근 30일)
이전 댓글 표시
I am trying to find a way to remove the whitespace that is right to the colorbar but it seems to be rather tricky. Any ideas?
Thanks!
close all;
clear all;
clc;
A = 1;
f = 50;
T = 1/f;
w = 2*pi*f;
x1 = linspace(0,T,1000)';
y1 = A.*sin(w.*x1);
x2 = 1:10;
y2 = rand(10);
f1 = figure(1);
yyaxis left
p1 = plot(x1,y1);
ylabel('Var 1')
yyaxis right
p2 = plot(x2,y2,'o');
ylabel('Var 2')
xlabel('X var')
c = colorbar;
c.Label.FontSize = 7;
c.Color = [0 0 0];
c.Ticks = [0:0.2:1];
c.Label.String = 'Density (normalised)';
ax = gca;
ax.FontName = 'Garamond';
ax.FontSize = 7;
set(gcf,'units','centimeters','position',[10 10 6.93 6.93/2])
댓글 수: 0
채택된 답변
Dave B
2021년 11월 19일
편집: Dave B
2021년 11월 19일
Do you mean in an export or as displayed in the figure window?
Here's what I get with your code and: exportgraphics(gcf,'foo.png'). This is with your position set and default dpi, so it's low res. If you select it you'll see the image boundary runs tightly alongside the colorbar label.
And here's tiledlayout/nexttile
t=tiledlayout(1,1,'Padding','tight');
nexttile
A = 1;
f = 50;
T = 1/f;
w = 2*pi*f;
x1 = linspace(0,T,1000)';
y1 = A.*sin(w.*x1);
x2 = 1:10;
y2 = rand(10);
f1 = figure(1);
yyaxis left
p1 = plot(x1,y1);
ylabel('Var 1')
yyaxis right
p2 = plot(x2,y2,'o');
ylabel('Var 2')
xlabel('X var')
c = colorbar;
c.Label.FontSize = 7;
c.Color = [0 0 0];
c.Ticks = [0:0.2:1];
c.Label.String = 'Density (normalised)';
ax = gca;
ax.FontName = 'Garamond';
ax.FontSize = 7;
set(gcf,'units','centimeters','position',[10 10 6.93 6.93/2])
annotation('rectangle','Position',[0 0 1 1],'LineWidth',2) % for highlighting the figure boundary
댓글 수: 3
Dave B
2021년 11월 19일
It's really unfortunate the exportgraphics doesn't support svg. Sadly I can't think of a workaround other than to use another program to convert from a file format like .eps to .svg (I use adobe illustrator for this kind of thing but I suspect Ghostscript, which is free, might be able to do it). Sorry I don't have something better to offer!
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Orange에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!