- 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 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MichailM
am 19 Nov. 2021
Kommentiert: MichailM
am 19 Nov. 2021
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 Kommentare
Akzeptierte Antwort
Dave B
am 19 Nov. 2021
Bearbeitet: Dave B
am 19 Nov. 2021
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 Kommentare
Dave B
am 19 Nov. 2021
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!
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Orange finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!