Create a figure -exactly- a certain size
5 ビュー (過去 30 日間)
古いコメントを表示
Consider the following code:
N = 2000;
[X,Y] = meshgrid(linspace(0,2*pi,N),linspace(0,2*pi,N));
Z = sin(X+Y);
p = pcolor(X,Y,Z)
Effectively, this colors each of the NxN elements of the matrix Z a given color. If you're running this, change N to something smaller.
I want to generate a .png figure that is exactly N x N pixels, each pixel representing one of the elements of Z.
How would I do that?
Additional notes:
This almost does it.
set(p, 'EdgeColor', 'none');
set(gca, 'Visible', 'off')
set(gcf, 'Units', 'pixels', [100 100 N+200 N+200]);
set(gca, 'Units', 'pixels', [50 50 N N]);
export_fig 'test' -png
There are two problems with this code:
- If N is large, then the figure is the incorrect dimension. For example, if N = 2000, then it seems that the figure gets expanded only until the height of your screen is reached. I need to be able to create arbitrarily sized images. The screen display is not important.
- The resultant figures are N+2 times N+2 pixels. I think that it's the 'removed' axes borders. How do I make it exactly N x N pixels (without cropping or re-sizing with an image editor)?
3 件のコメント
採用された回答
Oliver Woodford
2012 年 8 月 8 日
export_fig (or rather, print) appears to only export that part of the figure which is on screen. Make the figure small and use the -mX option. E.g. make the axes half the size and use -m2. The output then still won't be exactly right, but a simple solution is to crop the image programmatically.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Lighting, Transparency, and Shading についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!