如何根据上一个图表中的键顺序构建新图表。 这是我的编码:
#!/usr/bin/env python
import matplotlib.pyplot as plt
from maxTPRlist import *
from max1TPRlist import *
from collections import OrderedDict
上一张图
plt.figure('FPR=0,TPR=?')
plt.title('FPR=0,TPR=?')
plt.ylabel('True Positive Rate(TPR)')
plt.xlabel('KO Files')
plt.ylim(ymax = 1.0000, ymin = 0.000)
plt.grid(True)
# I sort following the value
d_descending = OrderedDict(sorted(mTPRlist.items(),
key=lambda (k,v): (v,k), reverse=True))
plt.plot(range(len(d_descending)), d_descending.values(), label="FPR=0,TPR=?", marker='o', linestyle='-', color='b')
plt.xticks(range(len(d_descending)), list(d_descending.keys()), rotation=45)
plt.legend()
plt.show()
新图
plt.figure('FPR=1%,TPR=?')
plt.title('FPR=1%,TPR=?')
plt.ylabel('True Positive Rate(TPR)')
plt.xlabel('KO Files')
plt.ylim(ymax = 1.0000, ymin = 0.000)
plt.grid(True)
## I take the key from previous for x-axis and it sorted in the same way.
## But the order of value for y-axis is mistaken.
plt.plot(range(len(d_descending)), m1TPRlist.values(), label="FPR=1%,TPR=?", marker='o', linestyle='-', color='g')
plt.xticks(range(len(d_descending)), list(d_descending.keys()), rotation=45)
plt.legend()
plt.show()
这是我的数据示例。
mTPRlist={'K00855': '0.991', 'K02446': '0.762', 'K01689': '0.957', 'K03712': '0.974', 'K01622': '0.961'}
mTPRlist={'K00855': '0.992', 'K02446': '0.255', 'K01689': '0.151', 'K03712': '0.950', 'K01622': '0.187'}
我希望有人可以帮助我。