Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 多行打印和重新标记图例_Python_Pandas_Matplotlib - Fatal编程技术网

Python 多行打印和重新标记图例

Python 多行打印和重新标记图例,python,pandas,matplotlib,Python,Pandas,Matplotlib,1为什么线条如此密集 在数据集中,时间是以小时为单位的,如果时间是以天为单位的,那么它会有所不同。我想看看每个主机的折线图 2如何将图例从计数重新标记到主机 fig, ax = plt.subplots(figsize=(15,7)) df.groupby('host').plot(x='time', y='count',ax=ax, legend=True) Ad 2只需添加label='name'作为参数,即: fig, ax = plt.subplots(figsize=(15,7))

1为什么线条如此密集

在数据集中,时间是以小时为单位的,如果时间是以天为单位的,那么它会有所不同。我想看看每个主机的折线图

2如何将图例从计数重新标记到主机

fig, ax = plt.subplots(figsize=(15,7))
df.groupby('host').plot(x='time', y='count',ax=ax, legend=True)
Ad 2只需添加label='name'作为参数,即:

fig, ax = plt.subplots(figsize=(15,7))
df.groupby('host').plot(x='time', y='count',ax=ax, legend=True, label='host')
您正在绘制超过6个月的每小时数据。这是大约4k的数据点,当然是密集的。每日数据会更好,尽管它仍然会很密集

有两种选择:

你可以用

或在groupby上执行循环:


嗨,这是一篇文章中的两个问题。另外,请尝试提供一些自动化测试数据和一个最小的完整工作示例。如果您可以添加一些数据的小型数据库,那就太好了。我将数据集改为每周,图形看起来更好,groupby上的循环也很完美。谢谢
import seaborn as sns
fig, ax = plt.subplots(figsize=(15,7))
sns.lineplot(x='time', y='count', ax=ax, hue='host')
fig, ax = plt.subplots(figsize=(15,7))
for h, d in df.groupby('host'):
    d.plot(x='time', y='count', ax=ax, label=h)