# Plotting ratings matrix

Hello fellows and folks.

I have been looking to do this for 1 month and still cannot find the way to do it.

Here’s what’s going on:

I have a csv file called ratings.csv with the following structure:

userID, movieID, rating
3,  12, 5
2, 7,  4


The rating scale goes from 0 to 5 stars. I want to be able to plot the sparsity of the matrix like it’s done in the following picture:

As you can see, ratings scale goes from 0 to 5 on the right. It is a very well thought plot.

I have Matlab, Python, R etc. Could you come up with something and help me? I’ve tried hard but I cannot find the way to do it.

• I don't understand you question. Do you want to repeat the plot? – nicoguaro May 20 '19 at 0:08
• Yes, exactly! Thats the idea but I cannot find the way to do it. – NaveganTeX May 20 '19 at 0:28
• Anyway, your picture looks like it is simply the output of Matlab's imagesc(A), once you have converted the ratings to a sparse matrix A (which, I assume, you know how to do with spconvert or the three-argument version of sparse). – Federico Poloni May 20 '19 at 12:23
• Is your answer supposed to be an update to your post? – nicoguaro May 20 '19 at 15:30
• You just added code without any explanation, consider adding an explanation. Also, mentioning why @FedericoPoloni solution does not work. – nicoguaro May 20 '19 at 15:51

I was able to do it this way though it may had been easier to plot it the way Federico has mentioned before: imagesc(A).

I declared an A matrix of zeros of mxn dimension and then loaded the ratings. I then applied HeatMap(A) which yields the image below.

A = importdata('u.data');
user_id = A(:, 1);
movie_id = A(:, 2);
rating = A(:, 3);

% Build matrix R
R = zeros(943, 1682);

for i=1:100000
R(user_id(i), movie_id(i)) = rating(i);

end

m = HeatMap(R,’Xlabel’,’I did it!’)
ax = hm.plot; % 'ax' will be a handle to a standard MATLAB axes.
colorbar('Peer', ax); % Turn the colorbar on
caxis(ax, [0 5]); % Adjust the color limits