栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

将图像应用于pyplot python条形图

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

将图像应用于pyplot python条形图

尽管

matplotlib
确实允许条形图中的阴影线,但AFAIK没有内置的方法来执行此操作。参见例如hatch_demo。

但是

plt.imshow
,以条形图的形式组合多个调用并不困难。这是一个相当粗糙的函数,可以使用图像的标志思想将图像用作基本的条形图。

import numpy as npimport matplotlib.pyplot as pltfrom scipy.misc import imreaddef image_plot(heights, images, spacing=0):    # Iterate through images and data, autoscaling the width to    # the aspect ratio of the image    for i, (height, img) in enumerate(zip(heights, images)):        AR = img.shape[1] / img.shape[0]        width = height * AR        left = width*i + spacing*i        right = left + width        plt.imshow(img, extent=[left, right, 0, height])    # Set x,y limits on plot window    plt.xlim(0, right)    plt.ylim(0, max(heights)*1.1)# Read in flag imagesusa_flag = imread('american_flag.png')aussie_flag = imread('australian_flag.png').swapaxes(0, 1)turkish_flag = imread('turkish_flag.png').swapaxes(0, 1)# Make up some data about each countryusa_data = 33aussie_data = 36turkish_data = 27data = [usa_data, aussie_data, turkish_data]flags = [usa_flag, aussie_flag, turkish_flag]image_plot(data, flags, spacing=2)

在不对

x
y
轴进行任何操作的情况下,返回此图。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/625466.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号