Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scaling MATLAB/Octave plot so that all the labels can be printed properly

I am trying to create a simple heatmap using MATLAB/Octave: Heatmap plot
As you can see I have a lot of rows, each of which represents a separate category.

I am using the imagesc function and I would like to be able to scale the image/plot so that each of the y-axis labels could be printed properly (instead of having the mess that can be seen in the image below).

Here is a sample code that I would like to modify:

A = randi(100, 200, 3);
imagesc(A, limit = [0, 100]);
set(gca, 'xtick', [1:3]);
set(gca, 'xticklabel', { "1,000", "2,000", "3,000" });
set(gca, 'ytick', [1:200]);

Edit: I am attaching the solution to the proposed problem, reached thanks to EitanT's advice as well as the useful information at http://nibot-lab.livejournal.com/73290.html?nojs=1:

paperWidth = 16.5;
paperHeight = 11.7;

set(gcf, 'Position', get(0,'Screensize'));
set(gcf, 'PaperUnits', 'inches');
set(gcf, 'PaperSize', [paperHeight paperWidth]);
set(gcf, 'PaperPositionMode', 'manual');
set(gcf, 'PaperPosition', [0 0 paperWidth paperHeight]);
set(gcf, 'renderer', 'painters'); figure(gcf);

A = randi(100, 200, 3);
imagesc(A, limit = [0, 100]);
set(gca, 'FontSize', 5);
set(gca, 'FontWeight', 'light');
set(gca, 'xtick', [1:3]);
set(gca, 'xticklabel', { "1,000", "2,000", "3,000" });
set(gca, 'ytick', [1:200]);
like image 470
User3419 Avatar asked Nov 09 '12 19:11

User3419


1 Answers

There are a few possible solutions to this:

Resizing the figure window

If the figure is not maximized already, you can do it using:

set(gcf, 'Position', get(0, 'ScreenSize'))

Instead of get(0, 'ScreenSize') you can, of course, specify any desired dimensions with a custom vector (as described here).

Reducing the font size

You can also make the label text smaller simply by decreasing the font size:

set(gca, 'FontSize', 5)

Note that this, however, affects all text in the current axes.

Reducing the number of displayed ticks

As a last resort, you can reduce the number of displayed ticks in the y-axis, i.e increase the tick interval. Instead of 1:200, try playing with other intervals, for instance:

set(gca, 'YTick', [1:20:200])

Try a combination of the solutions described above, for better visualization.

You can read more about axis control in the official documentation. Also, as suggested by you in one of the comments, this page contains a lot of additional useful tricks for displaying plots in MATLAB.

like image 76
Eitan T Avatar answered Oct 12 '22 20:10

Eitan T