2016-10-31 6 views
1

画像が描かれたグラフを描画したい。私はk-meansクラスタリングをしています。その後、同じフレームカラーで各画像をクラスタに表示したいと思います。matplotlibを色の付いたフレームで表示するプロットの画像を表示する

私は基本的に私はscickit learnドキュメントにいくつかのチュートリアルをチェックしていたし、また私がいない結果とmatplotlib WebページでAnnotationBboxOffsetImageコンストラクタを確認

fig = plt.gcf() 
fig.clf() 
ax = plt.subplot(111) 

# add a first image 
for i in range(0, len(dataset['val'].path)):  
    ab = AnnotationBbox(OffsetImage(img, zoom=.15, cmap='gray'), 
         [reduced_data[i][0], reduced_data[i][1]], 
         frameon=True, 
         xybox=(10, 10), 
         xycoords='data', 
         boxcoords="offset points", 
         arrowprops=dict(arrowstyle="-")) 

    ax.add_artist(ab) 
plt.draw() 
plt.show() 

黒のフレームとグラフ上に画像を配置いくつかのコードを持っています。私はプロットに挿入された画像のフレームの色を変更して、各クラスターに与えている色と一致するようにする方法があるのだろうかと思っていました。

答えて

2

bboxprops=dict(edgecolor='red')を使用して、AnnotationBboxのバウンディングボックスを設定できます。 最小限たとえば、与え

import numpy as np 
import matplotlib.pyplot as plt 
from matplotlib.offsetbox import OffsetImage, AnnotationBbox 

fig, ax = plt.subplots() 
im = OffsetImage(np.arange(100).reshape((10, 10))) 
ab1 = AnnotationBbox(im, (0.5, 0.5), 
        bboxprops =dict(edgecolor='red')) 
ab2 = AnnotationBbox(im, (0.75, 0.75), 
        bboxprops =dict(edgecolor=[0.2,1.,0.5] )) 

ax.add_artist(ab1) 
ax.add_artist(ab2) 
plt.show() 

enter image description here

+0

それは働きます!ありがとうございました。 –

関連する問題