6

I have a Matrix that contains N users and K items. I want to plot that matrix in Python by considering each line as a vector with multiple coordinates. For example a simple point plot require X,Y. My vector hasK coordinates and I want to plot each one of those N vectors as a point to see there similarities. Can anyone help me with that ?

UPDATE:

#Matrix M shape = (944, 1683)
plt.figure()
plt.imshow(M, interpolation='nearest', cmap=plt.cm.ocean)
plt.colorbar()
plt.show()

but this gave me as result : enter image description here

What I want is something like that: enter image description here

6
  • Well, you should show us what you have tried so far! Commented Nov 3, 2014 at 9:40
  • SO is not a code writing service, please provide any code that you have written so far in a MCVE Commented Nov 3, 2014 at 9:41
  • I should've told you that I am a beginer in Python. I search like everywhere but I did not find anything that can resolve my problem. Commented Nov 3, 2014 at 9:48
  • I apdated the post @KlausD Commented Nov 3, 2014 at 9:57
  • 1
    Before searching or asking for implementations, you should think about what you are hoping to see as a result. Your example is a simple 2D scatter plot. But for plotting k-dimensional data you need some other concept, like euclidean embedding or parallel coordinates. Commented Nov 3, 2014 at 10:11

1 Answer 1

14

It is difficult from this question to be sure if my answer is relevant, but here's my best guess. I believe deltascience is asking how multidimensional vectors are generally plotted into two-dimensional space, as would be the case with a scatter plot. I think the best answer is that some kind of dimension reduction algorithm is generally performed. In other words, you don't do this by finding the right matplotlib code; you get your data into the right shape (one list for the X axis, and another list for the Y axis) and you then plot it using a typical matplotlib approach:

import numpy as np
import matplotlib.pyplot as plt
from sklearn.decomposition import PCA

M = np.random.rand(944, 1683)

pca = PCA(n_components=2)
reduced = pca.fit_transform(M)

# We need a 2 x 944 array, not 944 by 2 (all X coordinates in one list)
t = reduced.transpose()

plt.scatter(t[0], t[1])
plt.show()

Here are some relevant links:

https://stats.stackexchange.com/questions/63589/how-to-project-high-dimensional-space-into-a-two-dimensional-plane

http://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html

https://towardsdatascience.com/the-art-of-effective-visualization-of-multi-dimensional-data-6c7202990c57

https://www.evl.uic.edu/documents/etemadpour_choosingvisualization_springer2016.pdf

July 2019 Addendum: It didn't occur to me at the the time, but another way people often visualize multi-dimensional data is with network visualization. Each multi-dimensional array in this context would be a node, and the edge weight would be something like the cosine similarity of two nodes, or the Euclidian distance. Networkx in python has some really nice visualization options.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.