powder
powder

Reputation: 1173

Matlab plot F-score

First of all I apologize for this rather generic question. I have a data matrix where each row represent a different video and each column represent the f-measure that different object trackers achieve. I need to obtain a plot which looks like this:

enter image description here

I have been told that this plot can be obtained using matlab but I already checked the entire plot catalog without results..is there some magical way to obtain this that I'm missing?

Don't know if it helps, my data matrix looks like this:

0.5204    0.5187    0.4838    0.6406    0.4326    0.2271
0.2793    0.1177    0.1767    0.2397    0.2251    0.2138
0.2314    0.0206    0.5091    0.0698    0.4575    0.1406
0.0472    0.1602    0.6372    0.5745    0.3769    0.0294
0.1211    0.0333    0.4342    0.0801    0.0147    0.0389
0.2552    0.5786    0.2446    0.5532    0.3607    0.0984
0.0867    0.1457    0.0237    0.0294    0.1834    0.1492
0.1565    0.0973    0.1303    0.0879    0.1118    0.0756

Thanks for any input!

Upvotes: 2

Views: 1326

Answers (2)

rayryeng
rayryeng

Reputation: 104545

You can achieve this using the pcolor function. You would call it like so:

pcolor(C);

pcolor creates a pseudo-coloured checkerboard plot. You provide it a matrix C, and it will colour each element based on the elements provided in C using a colormap. The default colormap is jet. The various colour maps you can use look like this:

colormap
(source: mathworks.com)

Using jet, bluer values tend to gravitate to lower values while red values gravitate to higher values. Given the above plot in your post, copper seems to be the best fit. If you want to change the colour map, simply call pcolor to first produce the plot, then call colormap(str) where str is the name of the colour map you want to use. Take note that I didn't include single quotes with the name as it isn't a string. Also, pcolor's default behaviour is that the last row and last column are not used. However, the data will be used when plotting the checkerboard. As you want to use all the values in your matrix, we should pad the last row and last column with the minimum of all of your data. As F-scores contain 0, we can pad the last row and last column with zeroes.

As an example, let's create the plot using pcolor. We can also specify custom x and y axis labels as well to mimic what you see above in your post's figure. Assuming your data is stored in A, we can do:

%// Define your data matrix and store it in A first

figure;
Apad = [A zeros(size(A,1),1); zeros(1,size(A,2)) 0];
pcolor(Apad);
colormap(copper);
set(gca, 'XTick', 1.5:6.5);
set(gca, 'YTick', 1.5:8.5);
set(gca,'XTickLabel',{'Tracker 1', 'Tracker 2', 'Tracker 3', 'Tracker 4', 'Tracker 5', 'Tracker 6'});
set(gca,'YTickLabel',{'Video 1', 'Video 2', 'Video 3', 'Video 4', 'Video 5', 'Video 6', 'Video 7', 'Video 8'});
title('Plotting F-scores for each tracker and video');
axis ij; %// Flip co-ordinate system - IMPORTANT!

Take a look at what I did with the those four set statements. If you want the labels to be in the middle rather than where the grid is defined, I set the tick properties to start at the halfway mark in between each square, then progressed linearly by 1. Similarly, I customized the x and y labels per tick to be Tracker 1 - 6 and Video 1 - 8. You can change these strings to be whatever you wish that suits your purposes. Also, take note that I had to flip the co-ordinate system as the origin of the data when you're plotting with pcolor assume that it's at the lower left corner, when your data's origin is at the top left corner. If you want to escape this flipping, you can easily use @MacDuff's solution too.

The output I finally get is:

enter image description here

As you can see, darker values mean a lower F-score, while brighter values correspond to higher F-scores. Also take note that the video labels are inverted. Video 1 starts at the top while Video 8 is located at the bottom. Take note of this before you start changing the y labels to suit your purposes.

Hope this helps!

Upvotes: 2

marsei
marsei

Reputation: 7751

You can use imagesc

such as

imagesc(rand(3,3))

that will plot a 3x3 matrix. Colors are assigned automatically (minimum/maximum value = minimum/maximum color).

enter image description here

Upvotes: 2

Related Questions