0

I have two vectors x and y and a matrix such that z[i,j] = f(x[i], y[j])

I would like to plot z keeping on the axis the coordinates in x and y. In other words the point z[i, j] should stay in position x[i], y[j] in the plot.

I need to keep this relationship because I need to overlap different plots.

plt.imshow(z) does not work as z[i,j] is in position (i, j) and not (x[i], x[j])

How can I solve?

EDIT: I need a 2 dimensional representation

1 Answer 1

2

you possibly could use a scatter plot.

import matplotlib.pyplot as plt
import numpy as np
N = 40
X = np.random.rand(N)
Y = np.random.rand(N)
def f(x,y): #function f
    return x+y
Z = np.zeros([N,N])
for i in range(N):
    for j in range(N):
        Z[i,j] = f(X[i],Y[j])
        plt.scatter(X[i],Y[j],c=Z[i,j],s=40,vmin=0.0,vmax=2.0,cmap='viridis',marker='s')

plt.show()

enter image description here

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

1 Comment

See: stackoverflow.com/questions/38953668/… for a solution to avoid the scatterplot in a loop by using meshgrid.

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.