<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        【Python教程】繪制漂亮的柱狀圖

        來源:懂視網 責編:小采 時間:2020-11-27 14:16:49
        文檔

        【Python教程】繪制漂亮的柱狀圖

        【Python教程】繪制漂亮的柱狀圖:Matplotlib是基于Python語言的開源項目,其旨在為Python提供一個數據繪圖包,本文簡單介紹如何使用該程序包繪制漂亮的柱狀圖。導入命令1)設置工作環境%cd "F:\\Dropbox\\python"2)導入程序包import matplotlib.pyplot
        推薦度:
        導讀【Python教程】繪制漂亮的柱狀圖:Matplotlib是基于Python語言的開源項目,其旨在為Python提供一個數據繪圖包,本文簡單介紹如何使用該程序包繪制漂亮的柱狀圖。導入命令1)設置工作環境%cd "F:\\Dropbox\\python"2)導入程序包import matplotlib.pyplot
        Matplotlib是基于Python語言的開源項目,其旨在為Python提供一個數據繪圖包,本文簡單介紹如何使用該程序包繪制漂亮的柱狀圖。

        導入命令

        1)設置工作環境%cd "F:\Dropbox\python"2)導入程序包import matplotlib.pyplot as plt
        import numpy as np
        from matplotlib.image import BboxImage
        from matplotlib._png import read_png
        import matplotlib.colors
        from matplotlib.cbook import get_sample_data
        import pandas as pd3)讀取數據data=pd.read_csv("CAR.csv")4)定義并繪制圖像
        class RibbonBox(object):original_image = read_png(get_sample_data("Minduka_Present_Blue_Pack.png",asfileobj=False))cut_location = 70
        b_and_h = original_image[:,:,2]
        color = original_image[:,:,2] - original_image[:,:,0]
        alpha = original_image[:,:,3]
        nx = original_image.shape[1]def __init__(self, color):
        rgb = matplotlib.colors.colorConverter.to_rgb(color)im = np.empty(self.original_image.shape,
        self.original_image.dtype)im[:,:,:3] = self.b_and_h[:,:,np.newaxis]
        im[:,:,:3] -= self.color[:,:,np.newaxis]*(1.-np.array(rgb))
        im[:,:,3] = self.alphaself.im = imdef get_stretched_image(self, stretch_factor):
        stretch_factor = max(stretch_factor, 1)
        ny, nx, nch = self.im.shape
        ny2 = int(ny*stretch_factor)stretched_image = np.empty((ny2, nx, nch),
        self.im.dtype)
        cut = self.im[self.cut_location,:,:]
        stretched_image[:,:,:] = cut
        stretched_image[:self.cut_location,:,:] = 
        self.im[:self.cut_location,:,:]
        stretched_image[-(ny-self.cut_location):,:,:] = 
        self.im[-(ny-self.cut_location):,:,:]self._cached_im = stretched_image
        return stretched_image
        class RibbonBoxImage(BboxImage):
        zorder = 1def __init__(self, bbox, color,
        cmap = None,
        norm = None,
        interpolation=None,
        origin=None,
        filternorm=1,
        filterrad=4.0,
        resample = False,
        **kwargs
        ):BboxImage.__init__(self, bbox,
        cmap = cmap,
        norm = norm,
        interpolation=interpolation,
        origin=origin,
        filternorm=filternorm,
        filterrad=filterrad,
        resample = resample,
        **kwargs
        )self._ribbonbox = RibbonBox(color)
        self._cached_ny = Nonedef draw(self, renderer, *args, **kwargs):bbox = self.get_window_extent(renderer)
        stretch_factor = bbox.height / bbox.widthny = int(stretch_factor*self._ribbonbox.nx)
        if self._cached_ny != ny:
        arr = self._ribbonbox.get_stretched_image(stretch_factor)
        self.set_array(arr)
        self._cached_ny = nyBboxImage.draw(self, renderer, *args, **kwargs)if 1:
        from matplotlib.transforms import Bbox, TransformedBbox
        from matplotlib.ticker import ScalarFormatterfig, ax = plt.subplots()years = np.arange(2001,2008)
        box_colors = [(0.8, 0.2, 0.2),
        (0.2, 0.8, 0.2),
        (0.2, 0.2, 0.8),
        (0.7, 0.5, 0.8),
        (0.3, 0.8, 0.7),
        (0.4, 0.6, 0.3),
        (0.5, 0.5, 0.1),
        ]
        heights = data['price']fmt = ScalarFormatter(useOffset=False)
        ax.xaxis.set_major_formatter(fmt)for year, h, bc in zip(years, heights, box_colors):
        bbox0 = Bbox.from_extents(year-0.4, 0., year+0.4, h)
        bbox = TransformedBbox(bbox0, ax.transData)
        rb_patch = RibbonBoxImage(bbox, bc, interpolation="bicubic")ax.add_artist(rb_patch)
        ax.annotate(h,
        (year, h), va="bottom", ha="center")
        ax.set_title('The Price of Car')patch_gradient = BboxImage(ax.bbox,
        interpolation="bicubic",
        zorder=0.1,
        )
        gradient = np.zeros((2, 2, 4), dtype=np.float)
        gradient[:,:,:3] = [1, 1, 0.]
        gradient[:,:,3] = [[0.1, 0.3],[0.3, 0.5]]
        patch_gradient.set_array(gradient)
        ax.add_artist(patch_gradient)ax.set_xlim(years[0]-0.5, years[-1]+0.5)
        ax.set_ylim(0, 15000)5)保存圖像fig.savefig('The Price of Car.png')
        plt.show()

        輸出圖像如下

        979.jpg

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        【Python教程】繪制漂亮的柱狀圖

        【Python教程】繪制漂亮的柱狀圖:Matplotlib是基于Python語言的開源項目,其旨在為Python提供一個數據繪圖包,本文簡單介紹如何使用該程序包繪制漂亮的柱狀圖。導入命令1)設置工作環境%cd "F:\\Dropbox\\python"2)導入程序包import matplotlib.pyplot
        推薦度:
        標簽: 制作 柱狀圖 教程
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 亚洲AV综合色区无码一区爱AV| 免费一级特黄特色大片在线观看| 国产亚洲精品va在线| 日韩精品免费一线在线观看| 免费观看日本污污ww网站一区| 亚洲乱理伦片在线观看中字| 女人18毛片a级毛片免费| 日韩亚洲产在线观看| 免费无码又爽又刺激毛片| 亚洲码欧美码一区二区三区| 国产在线19禁免费观看国产| 免费在线观看一区| 亚洲国产成人爱av在线播放| igao激情在线视频免费| 亚洲午夜福利717| 最近免费字幕中文大全视频| 亚洲性一级理论片在线观看| 成年男女免费视频网站| 国产精品亚洲AV三区| 一本色道久久88综合亚洲精品高清| 一级看片免费视频| 亚洲人成人网站色www| 亚洲网站在线免费观看| 亚洲国产熟亚洲女视频| 免费一级一片一毛片| 拍拍拍无挡免费视频网站| 亚洲综合久久1区2区3区| 国产免费AV片在线播放唯爱网| 精品久久亚洲一级α| 久久亚洲欧洲国产综合| 久久精品无码专区免费东京热| 亚洲an日韩专区在线| 亚洲毛片网址在线观看中文字幕 | 亚洲中文字幕无码爆乳app| 国产精品免费看香蕉| 日韩a级无码免费视频| 亚洲人成网站18禁止久久影院| 免费鲁丝片一级在线观看| 福利免费在线观看| 亚洲一级片在线播放| 国产日产亚洲系列最新|