如何绘制远程图像(来自http url) [英] How to plot remote image (from http url)

查看:50
本文介绍了如何绘制远程图像(来自http url)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这一定很容易,但是如果不使用urllib模块和手动获取远程文件,我现在无法弄清楚

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

我想用远程图像覆盖绘图(比如说"http://matplotlib.sourceforge.net/_static/logo2.png"),并且imshow()imread()都不能加载图像.

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?

推荐答案

这确实很容易:

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()

这篇关于如何绘制远程图像(来自http url)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆