[英]how to plot the values in a set of key-value pairs with Python
Using Python I was wondering if there were a faster way to plot the values of A and B without going through the troubles of saving them into 2 different arrays 使用Python我想知道是否有一种更快的方法来绘制A和B的值,而无需麻烦将它们保存到2个不同的数组中
{'A': 0.7452920360819947, 'B': 0.5692557501718727}
{'A': 0.7680988343673212, 'B': 0.5495359141383478}
{'A': 0.7831645842999736, 'B': 0.5346174541475203}
{'A': 0.7910552458637528, 'B': 0.5262811670299319}
{'A': 0.7945325379936994, 'B': 0.5223904375178747}
{'A': 0.7959286672497986, 'B': 0.5207298780860258}
{'A': 0.7964656379225264, 'B': 0.5200471890029877}
{'A': 0.7966683078984395, 'B': 0.5197703896938074}
{'A': 0.7967441494752115, 'B': 0.5196586622041124}
{'A': 0.7967724046132105, 'B': 0.5196136079148447}
{'A': 0.7967829009034072, 'B': 0.5195954342272032}
Not sure, how the input is exactly given. 不确定输入的确切给出方式。 Anyhow, it's not that much pain to extract two arrays:
无论如何,提取两个数组并没有那么麻烦:
import pylab as pl
pairs = [
{'A': 0.7452920360819947, 'B': 0.5692557501718727},
{'A': 0.7680988343673212, 'B': 0.5495359141383478},
{'A': 0.7831645842999736, 'B': 0.5346174541475203},
{'A': 0.7910552458637528, 'B': 0.5262811670299319},
{'A': 0.7945325379936994, 'B': 0.5223904375178747},
{'A': 0.7959286672497986, 'B': 0.5207298780860258},
{'A': 0.7964656379225264, 'B': 0.5200471890029877},
{'A': 0.7966683078984395, 'B': 0.5197703896938074},
{'A': 0.7967441494752115, 'B': 0.5196586622041124},
{'A': 0.7967724046132105, 'B': 0.5196136079148447},
{'A': 0.7967829009034072, 'B': 0.5195954342272032},
]
pl.plot([p['A'] for p in pairs], [p['B'] for p in pairs], 'r-')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.