2016-04-30 9 views
1

私のJupyterノートには次のコードがあります。私は今までインターネットで見つかった人物の姿を変えるいくつかの方法を試みましたが、何も動作していないようです。また、オブジェクトはmatplotlibの中で生成され、変更された方法は、本当にとにかく私には意味がありませんので、私は必ずどこ次に行きませんよ...Matplotlib:与えられたコードレイアウトの図形を増やすためのフォーマット

とにかく、私のコードはスタンドのとおりです。

from sklearn.metrics import confusion_matrix 
import matplotlib.pyplot as plt 
import numpy as np 
%matplotlib inline 

def plot_confusion_matrix(cm, title='Confusion matrix',fontsize=8, names=None,cmap=plt.cm.Blues): 
    plt.imshow(cm, interpolation='nearest', cmap=cmap) 
    plt.title(title) 
    plt.colorbar() 
    for i in range(cm.shape[0]): 
     for j in range(cm.shape[1]): 
      plt.text(i, j, str(cm[i, j]), fontsize=fontsize) 
    if names != None: 
     tick_marks = np.arange(len(names)) 
     plt.xticks(tick_marks, names) 
     plt.yticks(tick_marks, names) 
    plt.tight_layout() 
    plt.ylabel('True label') 
    plt.xlabel('Predicted label') 



confusion_matrix_path = 'mnist_cnn/main_project/CNN_Completed_Models/mnist_cnn_C_confusion.npy' 
cmat = np.load(confusion_matrix_path) 
plot_confusion_matrix(cmat,"MNIST Net C: Confusion Matrix",fontsize=8, names=[0,1,2,3,4,5,6,7,8,9]) 




plt.figure(figsize=(20,20)) <----- This Line Here 




plt.show() 

plt.figure(figsize=(20,20))行は何もしません。私が見つけた多くの修正もありません。このプロットの寸法を変更するにはどうすればいいですか?

+0

死んだpngの代わりに。 – tacaswell

+0

あなたは 'pyplot'の状態マシンに問題があり、それをあなたのプロット方法にプロットするためにどの数字を渡すのかを '現在のFigure'というグローバルな状態に頼っています。代わりに 'Axes'オブジェクトを' plot_confusion_matrix'に渡すべきです。 http://matplotlib.org/faq/usage_faq.html#coding-styles – tacaswell

+0

を参照し、 '' plt.figure'は新しい図形を作成します(http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.figure )既存のFigureのサイズを変更しません。 – tacaswell

答えて

0

これは狂っていて、私には意味がありませんが、何かをプロットする前にplt.figure(figsize=(a,b))行を置くと動作します。私は本当にこれらのオブジェクトをどのように構造化したのか分かりません。

from sklearn.metrics import confusion_matrix 
import matplotlib.pyplot as plt 
import numpy as np 
%matplotlib inline 

def plot_confusion_matrix(cm, title='Confusion matrix',fontsize=8, names=None,cmap=plt.cm.Blues): 


    plt.figure(figsize=(10,10))  <---- Should Actually Go Here 



    plt.imshow(cm, interpolation='nearest', cmap=cmap) 
    plt.title(title) 
    plt.colorbar() 
    for i in range(cm.shape[0]): 
     for j in range(cm.shape[1]): 
      plt.text(i, j, str(cm[i, j]), fontsize=fontsize) 
    if names != None: 
     tick_marks = np.arange(len(names)) 
     plt.xticks(tick_marks, names) 
     plt.yticks(tick_marks, names) 
    plt.tight_layout() 
    plt.ylabel('True label') 
    plt.xlabel('Predicted label') 



confusion_matrix_path = 'mnist_cnn/main_project/CNN_Completed_Models/mnist_cnn_C_confusion.npy' 
cmat = np.load(confusion_matrix_path) 
plot_confusion_matrix(cmat,"MNIST Net C: Confusion Matrix",fontsize=8, names=[0,1,2,3,4,5,6,7,8,9]) 




plt.figure(figsize=(10,10)) <----- This Line Here 




plt.show() 

それがそのように動作し、なぜ私にはわからない...と私はDEF、それを説明して答えを受け入れるだろう...私はあなたが対話的な数字を得るnotebook` `%のm​​atplotlibのを使用することをお勧めし

+0

'plt.figure()'は新しいFigureを作成します。既にFigureがある場合は、 'fig.set_size_inches()'を使います。 'plt.'コマンドを使用している場合は、** fig ** = plt.gcf()を使用して** ** ** ** ** ** **を使用してください。 – MaxNoe

関連する問題