亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

python+matplotlib繪制簡單的海豚(頂點(diǎn)和節(jié)點(diǎn)的操作)

 更新時(shí)間:2018年01月02日 10:14:25   投稿:mengwei  
這篇文章主要介紹了python+matplotlib繪制簡單的海豚(頂點(diǎn)和節(jié)點(diǎn)的操作),具有一定借鑒價(jià)值,需要的朋友可以參考下

海豚

本文例子主要展示了如何使用補(bǔ)丁、路徑和轉(zhuǎn)換類繪制和操作給定的頂點(diǎn)和節(jié)點(diǎn)的形狀。

測試可用。

import matplotlib.cm as cm
import matplotlib.pyplot as plt
from matplotlib.patches import Circle, PathPatch
from matplotlib.path import Path
from matplotlib.transforms import Affine2D
import numpy as np

# Fixing random state for reproducibility
np.random.seed(19680801)


r = np.random.rand(50)
t = np.random.rand(50) * np.pi * 2.0
x = r * np.cos(t)
y = r * np.sin(t)

fig, ax = plt.subplots(figsize=(6, 6))
circle = Circle((0, 0), 1, facecolor='none',
        edgecolor=(0, 0.8, 0.8), linewidth=3, alpha=0.5)
ax.add_patch(circle)

im = plt.imshow(np.random.random((100, 100)),
        origin='lower', cmap=cm.winter,
        interpolation='spline36',
        extent=([-1, 1, -1, 1]))
im.set_clip_path(circle)

plt.plot(x, y, 'o', color=(0.9, 0.9, 1.0), alpha=0.8)

# Dolphin from OpenClipart library by Andy Fitzsimon
#    <cc:License rdf:about="http://web.resource.org/cc/PublicDomain">
#     <cc:permits rdf:resource="http://web.resource.org/cc/Reproduction"/>
#     <cc:permits rdf:resource="http://web.resource.org/cc/Distribution"/>
#     <cc:permits rdf:resource="http://web.resource.org/cc/DerivativeWorks"/>
#    </cc:License>

dolphin = """
M -0.59739425,160.18173 C -0.62740401,160.18885 -0.57867129,160.11183
-0.57867129,160.11183 C -0.57867129,160.11183 -0.5438361,159.89315
-0.39514638,159.81496 C -0.24645668,159.73678 -0.18316813,159.71981
-0.18316813,159.71981 C -0.18316813,159.71981 -0.10322971,159.58124
-0.057804323,159.58725 C -0.029723983,159.58913 -0.061841603,159.60356
-0.071265813,159.62815 C -0.080250183,159.65325 -0.082918513,159.70554
-0.061841203,159.71248 C -0.040763903,159.7194 -0.0066711426,159.71091
0.077336307,159.73612 C 0.16879567,159.76377 0.28380306,159.86448
0.31516668,159.91533 C 0.3465303,159.96618 0.5011127,160.1771
0.5011127,160.1771 C 0.63668998,160.19238 0.67763022,160.31259
0.66556395,160.32668 C 0.65339985,160.34212 0.66350443,160.33642
0.64907098,160.33088 C 0.63463742,160.32533 0.61309688,160.297
0.5789627,160.29339 C 0.54348657,160.28968 0.52329693,160.27674
0.50728856,160.27737 C 0.49060916,160.27795 0.48965803,160.31565
0.46114204,160.33673 C 0.43329696,160.35786 0.4570711,160.39871
0.43309565,160.40685 C 0.4105108,160.41442 0.39416631,160.33027
0.3954995,160.2935 C 0.39683269,160.25672 0.43807996,160.21522
0.44567915,160.19734 C 0.45327833,160.17946 0.27946869,159.9424
-0.061852613,159.99845 C -0.083965233,160.0427 -0.26176109,160.06683
-0.26176109,160.06683 C -0.30127962,160.07028 -0.21167141,160.09731
-0.24649368,160.1011 C -0.32642366,160.11569 -0.34521187,160.06895
-0.40622293,160.0819 C -0.467234,160.09485 -0.56738444,160.17461
-0.59739425,160.18173
"""

vertices = []
codes = []
parts = dolphin.split()
i = 0
code_map = {
  'M': (Path.MOVETO, 1),
  'C': (Path.CURVE4, 3),
  'L': (Path.LINETO, 1)}

while i < len(parts):
  code = parts[i]
  path_code, npoints = code_map[code]
  codes.extend([path_code] * npoints)
  vertices.extend([[float(x) for x in y.split(',')] for y in
           parts[i + 1:i + npoints + 1]])
  i += npoints + 1
vertices = np.array(vertices, float)
vertices[:, 1] -= 160

dolphin_path = Path(vertices, codes)
dolphin_patch = PathPatch(dolphin_path, facecolor=(0.6, 0.6, 0.6),
             edgecolor=(0.0, 0.0, 0.0))
ax.add_patch(dolphin_patch)

vertices = Affine2D().rotate_deg(60).transform(vertices)
dolphin_path2 = Path(vertices, codes)
dolphin_patch2 = PathPatch(dolphin_path2, facecolor=(0.5, 0.5, 0.5),
              edgecolor=(0.0, 0.0, 0.0))
ax.add_patch(dolphin_patch2)

plt.show()

效果如下:

總結(jié)

以上就是本文關(guān)于python+matplotlib繪制簡單的海豚(頂點(diǎn)和節(jié)點(diǎn)的操作)的全部內(nèi)容,希望對大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關(guān)專題,如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!

相關(guān)文章

  • Python算術(shù)運(yùn)算符實(shí)例詳解

    Python算術(shù)運(yùn)算符實(shí)例詳解

    這篇文章主要介紹了Python算術(shù)運(yùn)算符實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下
    2017-05-05
  • 關(guān)于Python中的 oct 函數(shù)與 min 函數(shù)

    關(guān)于Python中的 oct 函數(shù)與 min 函數(shù)

    本文主要介紹了Python oct 函數(shù)與 min 函數(shù);oct 函數(shù)是 Python 內(nèi)置函數(shù),主要將一個(gè)整數(shù)轉(zhuǎn)為八進(jìn)制,與 ord 函數(shù) / chr 函數(shù) 有點(diǎn)類似;min 函數(shù)返回給定參數(shù)的最小值,參數(shù)可以為序列語法,感興趣的小伙伴請繼續(xù)閱讀下文
    2021-09-09
  • 詳解基于django實(shí)現(xiàn)的webssh簡單例子

    詳解基于django實(shí)現(xiàn)的webssh簡單例子

    這篇文章主要介紹了基于 django 實(shí)現(xiàn)的 webssh 簡單例子,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-07-07
  • pytorch中torch.stack()函數(shù)用法解讀

    pytorch中torch.stack()函數(shù)用法解讀

    這篇文章主要介紹了pytorch中torch.stack()函數(shù)用法,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-04-04
  • NumPy中np.c_ 和 np.r_ 的區(qū)別小結(jié)

    NumPy中np.c_ 和 np.r_ 的區(qū)別小結(jié)

    np.c_和?np.r_是NumPy庫中兩個(gè)非常有用的函數(shù),它們分別用于按列和按行拼接數(shù)組本文主要介紹了NumPy中np.c_ 和 np.r_ 的區(qū)別小結(jié),具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-02-02
  • Python如何對齊字符串

    Python如何對齊字符串

    這篇文章主要介紹了Python如何對齊字符串,文中講解非常細(xì)致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-07-07
  • Python中通過property設(shè)置類屬性的訪問

    Python中通過property設(shè)置類屬性的訪問

    為了達(dá)到類似C++類的封裝性能,可以使用property來設(shè)置Python類屬性的訪問權(quán)限,本文就介紹一下Python中通過property設(shè)置類屬性的訪問,感興趣的可以了解一下,感興趣的可以了解一下
    2023-09-09
  • 35個(gè)Python編程小技巧

    35個(gè)Python編程小技巧

    從我開始學(xué)習(xí)python的時(shí)候,我就開始自己總結(jié)一個(gè)python小技巧的集合。后來當(dāng)我什么時(shí)候在Stack Overflow或者在某個(gè)開源軟件里看到一段很酷代碼的時(shí)候,我就很驚訝:原來還能這么做!,當(dāng)時(shí)我會(huì)努力的自己嘗試一下這段代碼,直到我懂了它的整體思路以后,我就把這段代碼加到我的集合里
    2014-04-04
  • Python集合set的交集和并集操作方法

    Python集合set的交集和并集操作方法

    這篇文章主要介紹了Python集合set的交集和并集操作方法小,python的set,是一個(gè)無序不重復(fù)元素集,?基本功能包括關(guān)系測試和消除重復(fù)元素本文講述了python中set集合的比較方法包括交集,并集,差集,下文更多詳細(xì)資料,需要的小伙伴可以參考一下
    2022-03-03
  • Python函數(shù)常見幾種return返回值類型

    Python函數(shù)常見幾種return返回值類型

    本文主要介紹了Python函數(shù)常見幾種return返回值類型,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-01-01

最新評論