custom python matlabplot

Add Parameters:

import matplotlib.pyplot as plt
import numpy as np
from itertools import cycle

from sklearn import svm, datasets
from sklearn.metrics import precision_recall_curve
from sklearn.metrics import average_precision_score
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import label_binarize
from sklearn.multiclass import OneVsRestClassifier

#load data
y_test = np.loadtxt('./y_test_201708101147.txt')
y_score = np.loadtxt('./y_score_201708101147.txt')

# Compute Precision-Recall and plot curve
precision = dict()
recall = dict()
threshold = dict()
for i in range(3):
    precision[i], recall[i], threshold[i] = precision_recall_curve(y_test[:, i], y_score[:, i])

# setup plot details
params = {'legend.fontsize': 30,
          'font.family':'sans-serif',
          'font.sans-serif':'Calibri',
          'figure.figsize': (15, 15),
         'axes.labelsize': 40,
         'axes.titlesize':40,
         'xtick.labelsize':30,
         'ytick.labelsize':30}
plt.rcParams.update(params)
colors = cycle(['navy', 'turquoise', 'darkorange', 'cornflowerblue', 'teal'])
className = ['s1', 'm1', 'max_s1_m1']
markerName = ['|', 'x', '^']
lw = 2

# Plot Precision-Recall curve for each class
plt.clf()
#plt.figure(figsize=(15,15))
#for i, color in zip(range(3), colors):
#    plt.plot(recall[i], precision[i], '{0}'.format(styleName[i]), markersize=4, label='Precision-Recall curve of {0}'.format(className[i]))

plt.plot(recall[0], precision[0], 'r^', markersize=6, label='Precision-Recall curve of s1')
plt.plot(recall[1], precision[1], 'b.', markersize=4, label='Precision-Recall curve of m1')
plt.plot(recall[2], precision[2], 'y--', markersize=6, label='Precision-Recall curve of max_s1_m1')
    
plt.plot(recall[0][:recall[0].size-1], threshold[0], color='cornflowerblue', lw=lw, label='Threshold-Recall curve of s1')

plt.
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('Recall')
plt.ylabel('Precision/Threshold')
plt.title('Precision-Recall curve to multi-class')
plt.legend(loc="lower right")
plt.savefig('tmp.pdf')
plt.show()

不新开窗口没法执行plt.show()

# This code is written in python
import matplotlib.pyplot as plt
import matplotlib.image as mpimg

# x-axis values
x_axis=[1,4,5,7]
# y-axis values
y_axis=[2,10,7,9]
# Plotting the points
plt.plot(x_axis, y_axis)

#grid is on
plt.grid()

# Saving the figure in local memory
plt.savefig('Figure1.png')

# # function to show the plot
# plt.show()
#不新开窗口没法show
plt.imshow(mpimg.imread('Figure1.png'))  
#不新开窗口没法show
plt.show() 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值