<p>You're looking for a <a href="https://en.wikipedia.org/wiki/Heat_map" rel="nofollow noreferrer">heatmap</a>. Check out e.g. <a href="https://stackoverflow.com/q/33282368/3924118">https://stackoverflow.com/q/33282368/3924118</a> (if you like Python more than the others). See also <a href="https://seaborn.pydata.org/generated/seaborn.heatmap.html" rel="nofollow noreferrer">this documentation</a>.</p>

CC BY-SA 4.0
2019-05-19T22:46:45.390Z
2019-05-20T14:02:52.760Z
2019-05-20T14:02:52.760Z
nbro
<p>I did it!</p>

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

% Build matrix R and w (weights matrix)
R = zeros(943, 1682);
w = zeros(943, 1682);
for i=1:100000
    R(user_id(i), movie_id(i)) = rating(i);
    w(user_id(i), movie_id(i)) = 1;
end


m = HeatMap(R)
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
</code></pre>

<p>Output:</p>

<p><a href="https://i.sstatic.net/qn3yn.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/qn3yn.png" alt="enter image description here"></a></p>

CC BY-SA 4.0
2019-05-20T03:34:29.500Z
2019-05-20T03:34:29.500Z
NaveganTeX
<p>I have a <code>.csv</code> file called <code>ratings.csv</code> with the following structure:</p>

<pre><code>userID, movieID, rating
3,      12,      5
2,      7,       6
</code></pre>

<p>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: </p>

<p><a href="https://i.sstatic.net/jtSLT.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/jtSLT.jpg" alt="pictiure"></a></p>

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

<p>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.</p>

<machine-learning><recommender-system><data-visualization>
How do I plot a matrix of ratings?
NaveganTeX
# How do I plot a matrix of ratings?

(Asked by: username_0 on 2019-05-19)

I have a .csv file called ratings.csv with the following structure:
userID, movieID, rating
3,      12,      5
2,      7,       6

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.

**Tags:** machine-learning, recommender-system, data-visualization


---

## 2 answers

### Answer by username_1 on 2019-05-19. Score: 2

You're looking for a [heatmap](https://en.wikipedia.org/wiki/Heat_map). Check out e.g. <https://stackoverflow.com/q/33282368/3924118> (if you like Python more than the others). See also [this documentation](https://seaborn.pydata.org/generated/seaborn.heatmap.html).


---

### Answer by username_0 on 2019-05-20. Score: 1

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

% Build matrix R and w (weights matrix)
R = zeros(943, 1682);
w = zeros(943, 1682);
for i=1:100000
    R(user_id(i), movie_id(i)) = rating(i);
    w(user_id(i), movie_id(i)) = 1;
end


m = HeatMap(R)
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

Output:


---

