2015-02-08 46 views
0
from matplotlib.pyplot import * 

例如,我有一個二維數組,下變量名存儲:「R」:Python(3.4.2)如何繪製具有給定半徑的二維數組作爲圓?

([[ 0.680979 , 0.8126483 ], 
    [ 0.4634487 , 0.14742914], 
    [ 0.27596818, 0.70073533], 
    [ 0.52843694, 0.54878972], 
    [ 0.13926434, 0.4223568 ], 
    [ 0.39956441, 0.31257942], 
    [ 0.06566612, 0.65883135], 
    [ 0.44879016, 0.33009628], 
    [ 0.68340944, 0.67422729], 
    [ 0.25075741, 0.08038742]]) 

我要繪製半徑r的圓在以下座標,例如磁盤1:

x-coordinate: 0.680979 y-coordinate:0.8126483 

我想所有的圓圈都繪製在1圖上。

回答

0

如果你想在屏幕指定圓的大小單位使用scatter

import matplotlib.pyplot as plt 
import numpy as np 

X, Y = np.array ([[ 0.680979 , 0.8126483 ], 
    [ 0.4634487 , 0.14742914], 
    [ 0.27596818, 0.70073533], 
    [ 0.52843694, 0.54878972], 
    [ 0.13926434, 0.4223568 ], 
    [ 0.39956441, 0.31257942], 
    [ 0.06566612, 0.65883135], 
    [ 0.44879016, 0.33009628], 
    [ 0.68340944, 0.67422729], 
    [ 0.25075741, 0.08038742]]).T 

r = 10 # in units of sq pixels 

fig, ax = plt.subplots() 
sc = ax.scatter(X, Y, s=r) 

scatter docs

,如果你想設置的大小數據單位:

import matplotlib.patches as mpatches 
import matplotlib.collections as mcoll 
fig, ax = plt.subplots() 
circles = [mpatches.Circle((x, y), radius=.1) for x, y in zip(X, Y)] 
coll = mcoll.PatchCollection(circles) 
ax.add_collection(coll) 
ax.set_aspect('equal') 
# you may have to set the x and y limits your self. 
ax.set_xlim(...) 
ax.set_ylim(...) 

circle docPatchCollection doc

+0

我接收到的錯誤如 無花果,AX = plt.subplots() NameError:名稱 'PLT' 沒有定義 – MasterWali 2015-02-08 22:26:27

+0

@RamanSB見編輯。增加鍋爐板進口。 – tacaswell 2015-02-08 22:31:07

相關問題