[英]Is it possible plot using ordered dictionary or list, OrderedDict doesn't work
I want to plot temperature decreasing in time. 我想绘制温度随时间降低。 The calculation is correct, my problem is that dictionary can NOT be in order.
计算是正确的,我的问题是字典不能按顺序排列。 I can sorted list in time.
我可以及时排序清单。 keys=time(1year,5year, 10year etc), values=temperature.
键=时间(1年,5年,10年等),值=温度。 I want sort by keys
我想按键排序
drawtemperature={}
for i, tau in enumerate(years):
for well in producers :
Temperature=[]
if len(reached) == 0:
Temperature.append(T0)
else:
sumQ=well.flow/nbcontours*len(reached)
Tm=((well.flow-sumQ)*T0+sumQ*Ti)/well.flow
Temperature.append(Tm)
drawtemperature[tau]=Temperature
dc=[drawtemperature[k] for k in sorted(drawtemperature)]
for k in dc:
pylab.plot(drawtemperature.keys(), drawtemperature.values())
pylab.show()
It drawing in wrong way, because of not ordering dictionary. 它以错误的方式绘制,因为没有排序字典。 The figure should be a piston like.
这个数字应该像活塞一样。 I couldn't post images, because I need at least 10 reputation(:
我无法发布图片,因为我需要至少10个声望(:
I know that I can't order dictionary, I've alreday tried OrderedDict from collection, but it doesn't work. 我知道我不能订购字典,我已经从集合中尝试了OrderedDict,但它不起作用。 Any idea?
任何想法?
Something like this? 像这样的东西? I assume you are trying to sort the dictionary by value
我假设您正在尝试按值对字典进行排序
pylab.plot(*zip(*sorted(dc.items(), key=lambda x:x[1])))
To switch the axes use this 要切换轴,请使用此功能
pylab.plot(*reversed(zip(*sorted(dc.items(), key=lambda x:x[1]))))
To sort by key, just leave the key=...
out 要按键排序,只需将
key=...
保留即可
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.