Is it possible to annotate a pyplot figure, but not with text or circles or the other similar objects, but an image instead?
For example read a png from a file and present it below a plotted data in the same graph.
This demo seems to do what you're looking for. Below is the the resulting plot:
Related
There are many ways to draw objects over 2d images. There are also many ways to draw 3D objects, as graphs over plots.
However, I did not find a way to draw 3D objects over 2D images. For example, let's say I want to draw a black cube over a picture:
Is there any Python package that enables this?
Never saw this in matplotlib to be honest. So here a littl workaround:
write 2 independent scripts, one for the plain background and one for the 3D object. Then you could merge them via Gimp, photoshop etc.
#for the background
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
plt.axis('off')
image = mpimg.imread("C:\path\to\image\xyz.jpg")
plt.imshow(image)
plt.show()
I already have some audio converted to spectrogram image using matplotlib.pyplot.specgram function.
After some operations on the image, now I would like to save it as an image file.
My simple thought was that since the data are already numpy arrays, I could just plot them.
The code was:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import imageio
im = imageio.imread(path/0.png')
plt.plot(im)
plt.show()
However, it returns very weird image as shown.
The image looks weird and obviously is not recognized as spectrograms
The original image was greyscale with shape (256, 128), how come the returned image has different colors?
What should I do now? Is it the wrong parameters setting that caused the results?
similar to the demonstration in https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.spectrogram.html, you should be using the plt.pcolormesh function instead of the plt.plot. Currently, you are plotting each of the spectrogram's lines separately.
I have a low resolution image that I want to scale up and display in a figure. As you might expect, the image looks a bit pixelated, so I would like to do some filtering on it. Matplotlib has filternorm and filterrad as filtering options in plt.imshow(), but they don't seem to do anything. The best I have been able to do is change the interpolation method to bicubic. I would like something where I can smoothly adjust the degree of filtering. Does anyone have any suggestions on how to do this using Matplotlib? I imagine I could import PIL or something from Scipy, but I'd like to avoid that.
Here is the raw image at it's native resolution (340x240)
Here is the matplotlib code
import matplotlib.pyplot as plt
im = plt.imread('path/on/my/computer')
im_obj = plt.imshow(im, interpolation = 'bicubic', resample = True)
plt.savefig('im_bicubic.png')
and here is the resulting png
I'm looking for a way to use matplotlib's 3D plotting
capabilities to display a flat image (a png or tiff) in 3D
space for some visualization I'd like to do.
The documentation is not very helpful,
is this even possible?
Here's a post that shows how to do what you're looking for.
Image overlay in 3d plot using python
Using basemap it's easy to plot a set of coordinates, like so:
x, y = m(lons, lats)
m.plot(x, y, 'go')
but would it be possible to use an image instead of the green circle ('go')? I didn't find a direct way of doing this from the documentation.
So, let's clarify this a bit: I'm using a map generated with basemap as a background and would like to plot some .png images on top of it instead of the regular plain markers.
If you want to draw .png images then you should try http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.imshow
You might also be interested in the Matplotlib Basemap toolkit. http://matplotlib.sourceforge.net/basemap/doc/html/
For your reference, I answered a similar question to this the other day: Python Matplotlib Basemap overlay small image on map plot