1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時(shí)間:8:30-17:00
      你可能遇到了下面的問題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      matplot繪圖-創(chuàng)新互聯(lián)

      Matplotlib

      Matplotlib 是一個(gè) Python 的 2D繪圖庫,通過 Matplotlib,開發(fā)者可以僅需要幾行代碼,便可以生成繪圖,直方圖,功率譜,條形圖,錯(cuò)誤圖,散點(diǎn)圖等。

      http://matplotlib.org

      創(chuàng)新互聯(lián)公司-成都網(wǎng)站建設(shè)公司,專注網(wǎng)站制作、做網(wǎng)站、網(wǎng)站營銷推廣,域名與空間,雅安服務(wù)器托管,綿陽服務(wù)器托管有關(guān)企業(yè)網(wǎng)站制作方案、改版、費(fèi)用等問題,請(qǐng)聯(lián)系創(chuàng)新互聯(lián)公司。
      • 用于創(chuàng)建出版質(zhì)量圖表的繪圖工具庫
      • 目的是為Python構(gòu)建一個(gè)Matlab式的繪圖接口
      • import matplotlib.pyplot as plt
      • pyplot模塊包含了常用的matplotlib API函數(shù)

      figure

      • Matplotlib的圖像均位于figure對(duì)象中
      • 創(chuàng)建figure:fig = plt.figure()

      示例代碼:

      # 引入matplotlib包
      import matplotlib.pyplot as plt
      import numpy as np
      
      %matplotlib inline #在jupyter notebook 里需要使用這一句命令
      
      # 創(chuàng)建figure對(duì)象
      fig = plt.figure()

      運(yùn)行結(jié)果:會(huì)彈出一個(gè)figure窗口,如下圖所示
      matplot繪圖

      subplot

      fig.add_subplot(a, b, c)

      • a,b 表示將fig分割成 a*b 的區(qū)域
      • c 表示當(dāng)前選中要操作的區(qū)域,
      • 注意:從1開始編號(hào)(不是從0開始)
      • plot 繪圖的區(qū)域是最后一次指定subplot的位置 (jupyter notebook里不能正確顯示)

      示例代碼:

      # 指定切分區(qū)域的位置
      ax1 = fig.add_subplot(2,2,1)
      ax2 = fig.add_subplot(2,2,2)
      ax3 = fig.add_subplot(2,2,3)
      ax4 = fig.add_subplot(2,2,4)
      
      # 在subplot上作圖
      random_arr = np.random.randn(100)
      #print random_arr
      
      # 默認(rèn)是在最后一次使用subplot的位置上作圖,但是在jupyter notebook 里可能顯示有誤
      plt.plot(random_arr)
      
      # 可以指定在某個(gè)或多個(gè)subplot位置上作圖
      # ax1 = fig.plot(random_arr)
      # ax2 = fig.plot(random_arr)
      # ax3 = fig.plot(random_arr)
      
      # 顯示繪圖結(jié)果
      plt.show()

      運(yùn)行結(jié)果:僅右下角有圖
      matplot繪圖

      直方圖:hist

      示例代碼:

      import matplotlib.pyplot as plt
      import numpy as np
      
      plt.hist(np.random.randn(100), bins=10, color='b', alpha=0.3)
      plt.show()

      matplot繪圖

      散點(diǎn)圖:scatter

      示例代碼:

      import matplotlib.pyplot as plt
      import numpy as np
      
      # 繪制散點(diǎn)圖
      x = np.arange(50)
      y = x + 5 * np.random.rand(50)
      plt.scatter(x, y)
      plt.show()

      matplot繪圖

      柱狀圖:bar

      示例代碼:

      import matplotlib.pyplot as plt
      import numpy as np
      
      # 柱狀圖
      x = np.arange(5)
      y1, y2 = np.random.randint(1, 25, size=(2, 5))
      width = 0.25
      ax = plt.subplot(1,1,1)
      ax.bar(x, y1, width, color='r')
      ax.bar(x+width, y2, width, color='g')
      ax.set_xticks(x+width)
      ax.set_xticklabels(['a', 'b', 'c', 'd', 'e'])
      plt.show()

      matplot繪圖
      matplot繪圖

      矩陣?yán)L圖:plt.imshow()

      • 混淆矩陣,三個(gè)維度的關(guān)系

      示例代碼:

      import matplotlib.pyplot as plt
      import numpy as np
      
      # 矩陣?yán)L圖
      m = np.random.rand(10,10)
      print(m)
      plt.imshow(m, interpolation='nearest', cmap=plt.cm.ocean)
      plt.colorbar()
      plt.show()

      plt.subplots()

      • 同時(shí)返回新創(chuàng)建的figure和subplot對(duì)象數(shù)組
      • 生成2行2列subplot:fig, subplot_arr = plt.subplots(2,2)
      • 在jupyter里可以正常顯示,推薦使用這種方式創(chuàng)建多個(gè)圖表

      示例代碼:

      import matplotlib.pyplot as plt
      import numpy as np
      
      fig, subplot_arr = plt.subplots(2,2)
      # bins 為顯示個(gè)數(shù),一般小于等于數(shù)值個(gè)數(shù)
      subplot_arr[1,0].hist(np.random.randn(100), bins=10, color='b', alpha=0.3)
      plt.show()

      運(yùn)行結(jié)果:左下角繪圖
      matplot繪圖

      顏色、標(biāo)記、線型

      • ax.plot(x, y, ‘r--’)

        等價(jià)于ax.plot(x, y, linestyle=‘--’, color=‘r’)

      示例代碼:

      import matplotlib.pyplot as plt
      import numpy as np
      
      fig, axes = plt.subplots(2)
      axes[0].plot(np.random.randint(0, 100, 50), 'ro--')
      # 等價(jià)
      axes[1].plot(np.random.randint(0, 100, 50), color='r', linestyle='dashed', marker='o')

      matplot繪圖

      • 常用的顏色、標(biāo)記、線型
        顏色
        • b: blue
        • g: grean
        • r: red
        • c: cyan
        • m: magenta
        • y: yellow
        • k: black
        • w: white

      標(biāo)記

        • .: point
        • ,: pixel
        • o: circle
        • v: triangle_down
        • ^: triangle_up
        • <: tiiangle_left

      線型

        • '-' or 'solid': solid lint
        • '--' or 'dashed': dashed line
        • '-.' or 'dashdot': dash-dotted line
        • ':' or 'dotted': dotted line
        • 'None': draw nothing
        • ' ': draw nothing
        • '': draw nothing

      刻度、標(biāo)簽、圖例

      • 設(shè)置刻度范圍

        plt.xlim(), plt.ylim()

        ax.set_xlim(), ax.set_ylim()

      • 設(shè)置顯示的刻度

        plt.xticks(), plt.yticks()

        ax.set_xticks(), ax.set_yticks()

      • 設(shè)置刻度標(biāo)簽

        ax.set_xticklabels(), ax.set_yticklabels()

      • 設(shè)置坐標(biāo)軸標(biāo)簽

        ax.set_xlabel(), ax.set_ylabel()

      • 設(shè)置標(biāo)題

        ax.set_title()

      • 圖例

        ax.plot(label=‘legend’)

        ax.legend(), plt.legend()
        loc=‘best’:自動(dòng)選擇放置圖例最佳位置

      示例代碼:

      import matplotlib.pyplot as plt
      import numpy as np
      
      fig, ax = plt.subplots(1)
      ax.plot(np.random.randn(1000).cumsum(), label='line0')
      
      # 設(shè)置刻度
      #plt.xlim([0,500])
      ax.set_xlim([0, 800])
      
      # 設(shè)置顯示的刻度
      #plt.xticks([0,500])
      ax.set_xticks(range(0,500,100))
      
      # 設(shè)置刻度標(biāo)簽
      ax.set_yticklabels(['Jan', 'Feb', 'Mar'])
      
      # 設(shè)置坐標(biāo)軸標(biāo)簽
      ax.set_xlabel('Number')
      ax.set_ylabel('Month')
      
      # 設(shè)置標(biāo)題
      ax.set_title('Example')
      
      # 圖例
      ax.plot(np.random.randn(1000).cumsum(), label='line1')
      ax.plot(np.random.randn(1000).cumsum(), label='line2')
      ax.legend()
      ax.legend(loc='best')
      #plt.legend()

      matplot繪圖

      另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。


      當(dāng)前題目:matplot繪圖-創(chuàng)新互聯(lián)
      轉(zhuǎn)載注明:http://ef60e0e.cn/article/ehido.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        宝坻区| 友谊县| 漳浦县| 通渭县| 炎陵县| 湛江市| 垦利县| 肥城市| 怀化市| 班玛县| 兴化市| 乌拉特前旗| 伽师县| 根河市| 吉木萨尔县| 徐汇区| 永清县| 德江县| 万山特区| 始兴县| 来凤县| 苍梧县| 日照市| 贵港市| 房产| 延寿县| 三亚市| 灵武市| 广南县| 台北县| 酒泉市| 谢通门县| 泾阳县| 衡东县| 都兰县| 当涂县| 皋兰县| 锡林浩特市| 海丰县| 治多县| 理塘县|