Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.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 pyplot输出不';我看起来不对劲_Python_Seaborn - Fatal编程技术网

Python pyplot输出不';我看起来不对劲

Python pyplot输出不';我看起来不对劲,python,seaborn,Python,Seaborn,这里提出的第一个问题。我希望我做得对。请让我知道,如果我应该提供更多的信息或如果我的问题不清楚 我正在尝试使用python(pandas、seaborn、matplotlib)生成一个折线图。经过多次尝试后,脚本运行了,但输出看起来不正确。原始数据比脚本输出上显示的平滑得多。我将其与excel中生成的图形进行了比较,后者看起来更真实。我真的不明白我的剧本出了什么问题 数据集为“马来西亚离岸价RBD棕榈油”的每日收盘市场价格。第1列是日期,第2列是价格。数据保存为CSV。我能想到的唯一问题是市场关

这里提出的第一个问题。我希望我做得对。请让我知道,如果我应该提供更多的信息或如果我的问题不清楚

我正在尝试使用python(pandas、seaborn、matplotlib)生成一个折线图。经过多次尝试后,脚本运行了,但输出看起来不正确。原始数据比脚本输出上显示的平滑得多。我将其与excel中生成的图形进行了比较,后者看起来更真实。我真的不明白我的剧本出了什么问题

数据集为“马来西亚离岸价RBD棕榈油”的每日收盘市场价格。第1列是日期,第2列是价格。数据保存为CSV。我能想到的唯一问题是市场关闭的日子。这可能是问题所在吗

代码如下:

import pandas as pd
df = pd.read_csv("/Users/michaelkingston/Desktop/RBDP2015_20.csv")
print(df)
df.info()
df['ds']= pd.to_datetime(df['ds'])
df.info()
import seaborn as sns
sns.lineplot(x="ds",
        y="Y",
        data=df)
import matplotlib.pyplot as plt
plt.show()
这是excel输出的图像

下面是python输出

打印(测向头)

根据数据,我觉得您的输出是正确的,它与您在excel中获得的结果不同,因为python的绘图被压缩为默认的绘图大小,您可以调整绘图的大小以像在excel中一样拉伸它。 另一点是:如果您需要excel中的x轴标签,那么最好不要将日期列转换为datetime对象,因为在打印datetime对象时,matplotlib仅显示几个日期以确保可读性

以下是您可以尝试的内容:

import matplotlib.pyplot as plt    

#converting the column ds to string type    
df['ds'] = df['ds'].astype(str)    

#fixing a big figure size for the plot    
plt.figure(figsize=(25,10))

sns.lineplot(x="ds", y="Y", data=df)

#for making the x-axis labels rotate by 90 degree to avoid cluttering of tick labels    
plt.xticks(rotation=90)
plt.show()

您能提供一些示例数据和代码的输出,以及您期望的结果吗?您好,我编辑了注释以显示excel图形输出和python图形输出。很抱歉,我不知道如何上传数据集的.csv文件。你能至少给我们看看df.head()吗?只需将它粘贴到这里,就好像它是代码一样。您好,我已经更新为包含print(df.head)。我希望这会有帮助。您可以看到,对于非交易日(例如2015-03-01、2015-04-01),实际上存在空值。我怀疑这可能是问题所在。非常感谢您的反馈。我会尝试一下谢谢你@Arvind Kumar,解决了这个问题。现在输出看起来是正确的。谢谢你的帮助。非常感谢。我很高兴它对我有帮助。
import matplotlib.pyplot as plt    

#converting the column ds to string type    
df['ds'] = df['ds'].astype(str)    

#fixing a big figure size for the plot    
plt.figure(figsize=(25,10))

sns.lineplot(x="ds", y="Y", data=df)

#for making the x-axis labels rotate by 90 degree to avoid cluttering of tick labels    
plt.xticks(rotation=90)
plt.show()