简体   繁体   English

如何在matplotlib中保存外观图像?

[英]How save apparent image in matplotlib?

I have already tried many ways. 我已经尝试了很多方法。 But it still same. 但还是一样。 I want to save a clear image. 我想保存清晰的图像。 This is my coding: 这是我的编码:

#!/usr/bin/env python
import matplotlib.pyplot as plt
from collections import OrderedDict
from output import *
from maxList import *

print "Total KO in Graph: ",len(mList)
# Max Fscore vs TPR vs FPR vs FDR
plt.title('Max Fscore vs TPR vs FPR vs FDR')
plt.ylabel('Value')
plt.xlabel('KO Files')
plt.ylim(ymax = 1.0000, ymin = 0.000)
plt.grid(True)
d_descending = OrderedDict(sorted(mList.items(), key=lambda x: x[1]['max'], reverse=True))

maximum=[float(x['max']) for x in d_descending.values()]
TPR=[float(x['TPR']) for x in d_descending.values()]
FPR=[float(x['FPR']) for x in d_descending.values()]
FDR=[float(x['FDR']) for x in d_descending.values()]
plt.plot(range(len(d_descending)), maximum, label="Max Fscore", marker='o', linestyle='-', color='r', linewidth=3)
plt.plot(range(len(d_descending)), TPR, label="TPR value", marker='o', linestyle='-', color='b')
plt.plot(range(len(d_descending)), FPR, label="FPR value", marker='o', linestyle='-', color='g')
plt.plot(range(len(d_descending)), FDR, label="FDR value", marker='o', linestyle='-', color='m')
plt.xticks(range(len(d_descending)), list(d_descending.keys()), rotation=90, fontsize=8)
lgd = plt.legend(loc='center left', bbox_to_anchor=(1, 0.5))
plt.savefig('Max Fscore vs TPR vs FPR vs FDR.png', bbox_extra_artists=(lgd,), bbox_inches='tight', figsize=(10, 8), dpi=100)
plt.show()
plt.close()

But the image save is not clear. 但是图像保存不清楚。 The x-axis it difficult to read. x轴很难读取。 在此处输入图片说明

One option is to show only every second tick and label: 一种选择是仅每秒显示一次刻度和标签:

plt.xticks(list(range(len(d_descending)))[::2], list(d_descending.keys())[::2], 
           rotation=90, fontsize=8)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM