-1

I keep receiving:

TypeError: Invalid dimensions for image data

with a blank graph that has axis going from 0.0 to 1.0 on both sides

import numpy as np  
import matplotlib.pyplot as plt  
from numpy import sin,cos,sqrt,arctan2  
from pylab import plot,show,xlabel,ylabel,linspace,ylim  

D = 50

x = linspace(0,D,1000)  
y = linspace(0,D,1000)

r1 = sqrt((x**2)+(y*2)) 

def function1():  
    f1 = sin(r1)  
    return f1  

function1()

plt.imshow(r1,origin='lower',extent=[0,10,0,5])  
plt.colorbar()  
plt.show()
0

1 Answer 1

0

plt.imshow() is expecting to receive a two-dimensional array (i.e. one with an x and y axis), but r1 is one-dimensional (i.e. it is just a flat list of numbers). You can fix this with the reshape method of numpy arrays:

r1 = r1.reshape(10,100)

This will convert your list of 1000 numbers into 10 rows of 100 numbers. I arbitrarily chose 10 and 100 as a pair of numbers that multiply out to 1000. You should replace them with whatever you want the actual x and y dimensions of the image to be.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.