I am trying to create a simple heatmap using MATLAB/Octave:
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]);
There are a few possible solutions to this:
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).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With