Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot remote image (from http url)

Tags:

matplotlib

This must be easy, but I can't figure how right now without using urllib module and manually fetching remote file

I want to overlay plot with remote image (let's say "http://matplotlib.sourceforge.net/_static/logo2.png"), and neither imshow() nor imread() can load the image.

Any ideas which function will allow loading remote image?

like image 900
theta Avatar asked Aug 24 '12 20:08

theta


People also ask

How do I download an image from URL SwiftUI?

Using AsyncImage to download remote imagesstruct ContentView: View { var body: some View { AsyncImage(url: URL(string: "https://picsum.photos/200/300")!) } } The above code results in a random fetched image every time the view appears: Downloading and caching an image in SwiftUI is an everyday use case.


3 Answers

It is easy indeed:

import urllib2
import matplotlib.pyplot as plt

# create a file-like object from the url
f = urllib2.urlopen("http://matplotlib.sourceforge.net/_static/logo2.png")

# read the image file in a numpy array
a = plt.imread(f)
plt.imshow(a)
plt.show()
like image 110
Daniel Avatar answered Nov 17 '22 14:11

Daniel


This works for me in a notebook with python 3.5:

from skimage import io
import matplotlib.pyplot as plt

image = io.imread(url)
plt.imshow(image)
plt.show()
like image 40
Julian Avatar answered Nov 17 '22 16:11

Julian


you can do it with this code;

from matplotlib import pyplot as plt
a = plt.imread("http://matplotlib.sourceforge.net/_static/logo2.png")
plt.imshow(a)
plt.show()
like image 14
crowdy Avatar answered Nov 17 '22 14:11

crowdy