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()