Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.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 Seaborn Rely轴无组织_Python_Pandas_Seaborn - Fatal编程技术网

Python Seaborn Rely轴无组织

Python Seaborn Rely轴无组织,python,pandas,seaborn,Python,Pandas,Seaborn,我有一个与此类似的数据帧: df=pd.DataFrame({ 'time' : ['00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00'], 'count_a' : ['1', '7', '12', '3', '1', '8', '4'], 'count_b' : ['3', '9', '5', '1', '3', '12', '1'], 'count_c' : ['10', '5', '1',

我有一个与此类似的数据帧:

df=pd.DataFrame({
    'time' : ['00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00'],
    'count_a' : ['1', '7', '12', '3', '1', '8', '4'],
    'count_b' : ['3', '9', '5', '1', '3', '12', '1'],
    'count_c' : ['10', '5', '1', '15', '9', '3', '9']
    })
我试图创建一个线条图,其中x=时间,色调=['count_a','count_b','count_c'),因此我使用pd.melt并绘制:

df_melted = df.melt('time', var_name='counts', value_name='amount' )
sns.relplot(data=df_melted, x='time', y='amount', hue='counts', kind='line', marker='o')
plt.show()
它给出了以下图表:

我需要的是,x='time'仍然以升序排列,y='amount'也以升序排列


想知道数据格式是否可用,如果可用,如何按升序排列y轴。

问题是您的数据存储在字符串中,您需要将其转换为实际数字,以便正确绘制

替换此行:

df_melted = df.melt('time', var_name='counts', value_name='amount')
为此:

df_melted = df.melt('time', var_name='counts', value_name='amount').astype({"amount": "int"})
或者,这是:

df_melted = df.melt('time', var_name='counts', value_name='amount')
df_melted["amount"] = pd.to_numeric(df_melted["amount"])

您应该使用
.astype()
pd.to\u numeric()
将您的值转换为数字。顺便说一句,您不需要在此处熔化…
sns.relplot(data=df.set\u index(“time”))
应该可以工作。