日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

小试牛刀Matplotlib

發布時間:2025/3/16 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 小试牛刀Matplotlib 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、plt.subplot()

import matplotlib.pyplot as plt# Integer subplot specification must be a three digit number # 前兩位代表橫豎長度比 # 左邊的代表橫,中間的代標縱坐標,右邊的則表示繪圖位置(當橫縱比不是1:1時) ax1, ax2, ax3 = plt.subplot(231), plt.subplot(232), plt.subplot(233) ax4, ax5, ax6 = plt.subplot(234), plt.subplot(235), plt.subplot(236) # 被注釋的地方xy(x, y)和插入文本的地方xytext(x, y) ax2.annotate("Test", xy=(0.5, 0.5), xycoords=ax1.transData,xytext=(0.5, 0.5), textcoords=ax2.transData,arrowprops=dict(arrowstyle="<-")) ax3.annotate("ax3", xy=(0.5, 0.5), xytext=(0.5, 0.5)) ax4.annotate("ax4", xy=(0.5, 0.5), xytext=(0.5, 0.5)) ax5.annotate("ax5", xy=(0.5, 0.5), xytext=(0.5, 0.5)) ax6.annotate("ax6", xy=(0.5, 0.5), xytext=(0.5, 0.5)) plt.show()

2、annotate

  • 被注釋的地方xy(x, y)和插入文本的地方xytext(x, y)
  • xycoords和textcoords指定xy和xytext的坐標系。默認為data(使用軸域數據坐標系)

| 參數 | 坐標系 |?

|? 'figure points' ?| 距離圖形左下角的點數量 |?
|? 'figure pixels' ?| 距離圖形左下角的像素數量 |?
|? 'figure fraction' ?| 0,0 是圖形左下角,1,1 是右上角 |?
|? 'axes points' ?| 距離軸域左下角的點數量 |?
|? 'axes pixels' ?| 距離軸域左下角的像素數量 |?
|? 'axes fraction' ?| 0,0 是軸域左下角,1,1 是右上角 |?

|?'data'?| 使用軸域數據坐標系 |

import matplotlib.pyplot as plt from numpy import *ax1 = plt.subplot(111)t = arange(0.0, 5.0, 0.01) s = cos(2*pi*t) line = plt.plot(t, s, lw=2) # 被注釋的地方xy(x, y)和插入文本的地方xytext(x, y) # xycoords和textcoords指定xy和xytext的坐標系。默認為data(使用軸域數據坐標系)ax1.annotate('local max', xy=(2, 1), xytext=(3, 1.5),arrowprops=dict(facecolor='black'))plt.ylim(-2, 2) plt.show()

3、在機器學習實戰的第三章,我們還用到了箭頭(arrow)和文本框(box)

import matplotlib.pyplot as plt# boxstyle文本框樣式, fc(face color)背景透明度 decisionNode = dict(boxstyle="round4, pad=0.5", fc="0.8") leafNode = dict(boxstyle="circle", fc="0.8") # 箭頭樣式 arrow_args = dict(arrowstyle="<-")def plotNode(nodeTxt, centerPt, parentPt, nodeType):createPlot.ax1.annotate(nodeTxt, xy=parentPt, xycoords="axes fraction",xytext=centerPt, textcoords="axes fraction", va="center",ha="center", bbox=nodeType, arrowprops=arrow_args)def createPlot():fig = plt.figure(1, facecolor="white")fig.clf()createPlot.ax1 = plt.subplot(111, frameon=False)plotNode('決策點', (0.5, 0.1), (0.1, 0.5), decisionNode)plotNode('葉節點', (0.8, 0.1), (0.3, 0.8), leafNode)# plt.rcParams['font.sans-serif'] = ['SimHei']plt.show()createPlot()

  • Annotating with Text with Box:boxstyle

Class

Name

Attrs

Circle

circle

pad=0.3

DArrow

darrow

pad=0.3

LArrow

larrow

pad=0.3

RArrow

rarrow

pad=0.3

Round

round

pad=0.3,rounding_size=None

Round4

round4

pad=0.3,rounding_size=None

Roundtooth

roundtooth

pad=0.3,tooth_size=None

Sawtooth

sawtooth

pad=0.3,tooth_size=None

Square

square

pad=0.3


  • Annotating with Arrow:arrowstyle

Name

Attrs

-

None

->

head_length=0.4,head_width=0.2

-[

widthB=1.0,lengthB=0.2,angleB=None

|-|

widthA=1.0,widthB=1.0

-|>

head_length=0.4,head_width=0.2

<-

head_length=0.4,head_width=0.2

<->

head_length=0.4,head_width=0.2

<|-

head_length=0.4,head_width=0.2

<|-|>

head_length=0.4,head_width=0.2

fancy

head_length=0.4,head_width=0.4,tail_width=0.4

simple

head_length=0.5,head_width=0.5,tail_width=0.2

wedge

tail_width=0.3,shrink_factor=0.5







總結

以上是生活随笔為你收集整理的小试牛刀Matplotlib的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。