In the following simple matplotlib code:
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0,5,0.1)
y = np.sin(1.33*x)
x1, y1 = np.meshgrid(x, y)
data = np.sin(x1) + y1**4
im = plt.imshow(data)
x = im.make_image()
...
I get the following inexplicable error in the last statement: "TypeError: make_image() takes at least 2 arguments (1 given)" And I get an even more ridiculous error if I use an argument, e.g.
x = im.make_image(magnification=2.0)
"TypeError: make_image() takes at least 2 arguments (2 given)". This is one of the most ridilulous programming errors I have ever come upon!
I have found the missing ingredient: its a renderer. E.g.
r = plt.gcf().canvas.get_renderer()
x = im.make_image(r, magnification=2.0)
This works. Meanwhile, however, I found out with the help of a commentator here that this make_image
function is not of any real use, and it is not much supported. Image maginifcation must be obtained with other means, e.g. axes.
So I consider the question solved. Thank you.
See e.g. this question for why something like
TypeError: method() takes at least n arguments (n given)
is not as ridiculous as it may sound at first sight.
Here you are calling make_image
without any positional argument. The signature, however, is
make_image(renderer, magnification=1.0, unsampled=False)
So you are missing the renderer
argument.
In python 3.6 the error is a little more clear. It would say something like
TypeError: make_image() missing 1 required positional argument: 'renderer'
which allows to find out the problem more easily.
Apart the question stays unclear on what the desired outcome is, so that's about what one can say at this point.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With