自另一个文件以来,如何将值插入到matplotlib列表中? [英] how to insert value into list of matplotlib since an other file?

查看:49
本文介绍了自另一个文件以来,如何将值插入到matplotlib列表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在py中有此脚本:

show_grid = True

with plt.style.context(('seaborn-darkgrid')):
    plt.plot([?, ?, ?, ?, ?, ?, ?, ?], [?, ?, ?, ?, ?, ?, ?, ?]) # the lists
    plt.ylabel('Temperatures °C')
    plt.xlabel('Dates')
    plt.title('Relevé des températures du mois de FEVRIER 2020')
    plt.grid(show_grid)
    plt.show()

,我想从其他文件(例如txt或json)中添加值:

and i would like to add values from an other file such as txt or json :

{'dicolist': ['22/02/2020', '+22.5']}

我应该如何进行plz,哪种格式更好?

How should i proceed plz, and which format is better ?

dicolist=dict_keys(['02/02/2020']):dict_values(['+23.0'])

[
{key,value}
{key,value}
{key,value}
{key,value}
]

救救我!! ?? :D

Help me !!??? :D

推荐答案

我仍然不太清楚您是否已经拥有词典或需要确定其格式.如果我对您的理解正确,则可以使用以下示例:

I still have not really clear if you have already your dictionary or you have to decide the format of it. If I understood you correctly you can make like the following example:

import matplotlib.pyplot as plt
from datetime import datetime

dicolist = {'22/02/2020': '+22.5', '23/02/2020': '+18'}
list_a = ['19/02/2020','20/02/2020','21/02/2020'] # your lists
list_b = ['+20.5','+21.5', '+19'] # your lists

for key, value in dicolist.items():
    list_a.append(key)
    list_b.append(value)

list_a = [datetime.strptime(d, '%d/%m/%Y') for d in list_a]
list_b = [float(d) for d in list_b]

show_grid = True
with plt.style.context(('seaborn-darkgrid')):
    plt.plot(list_a,list_b) # the lists
    plt.ylabel('Temperatures °C')
    plt.xlabel('Dates')
    plt.title('Relevé des températures du mois de FEVRIER 2020')
    plt.xticks(rotation=45)
    plt.grid(show_grid)
    plt.show()

这篇关于自另一个文件以来,如何将值插入到matplotlib列表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆