Save just part of the figure

22 ビュー (過去 30 日間)
BN
BN 2020 年 9 月 12 日
コメント済み: Ameer Hamza 2020 年 9 月 13 日
Dear all, I generate my color bar using this code
ax = axes;
colormap (flipud(cool(10)))
caxis([0 1])
c = colorbar(ax,'southoutside');
ax.Visible = 'off';
here is the result of the above code which I wnat to save it:
and try to save it via ".SVG" format using:
cd 'F:\university'
set(gcf,'PaperOrientation','landscape');
set(gcf,'PaperUnits','normalized')
set(gcf,'PaperPosition',[0 0 .36 .36]);
print(gcf,'COLORBAR.svg','-dsvg');
But after that, there is a huge white space in the top of the color bar appears. Is there any way to save just a color bar? I read about exportfig and exportgraphic but unfortunately they unable to save figures as SVG format. so I thought it can be done using ax properties so I tried this
set(gca, 'units', 'normalized'); %Just making sure it's normalized
Tight = get(gca, 'TightInset'); %Gives you the bording spacing between plot box and any axis labels
%[Left Bottom Right Top] spacing
NewPos = [Tight(1)+.02 Tight(2)+.02 1-Tight(1)-Tight(3)-0.06 1-Tight(2)-Tight(4)-0.06]; %New plot position [X Y W H]
set(gca, 'Position', NewPos);
But it not accomplished well.
Are you know how I can save just the color bar as SVG format?
Thank you so much

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 9 月 12 日
I think the easiest solution might be to export to eps format (which is also vector format) and then some other tool to generate svg. The following command will directly create eps file without any extra space.
f = figure;
ax = axes;
colormap(flipud(cool(10)))
caxis([0 1])
c = colorbar(ax,'southoutside');
ax.Visible = 'off';
exportgraphics(gcf, 'test.eps', ...
'ContentType', 'vector')
  2 件のコメント
BN
BN 2020 年 9 月 12 日
Thank you, It was really helpful. that's a very awesome trick. I do it and my problem solved. Thank you so much.
Ameer Hamza
Ameer Hamza 2020 年 9 月 13 日
I am glad to be of help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by