以DataFrame格式使用Google价格的简单示例。 Gadfly图给出了以下错误:TypeError(u'There is no Line2D property "y"',)
。也出于某种原因引用了matplotlib。
此处的代码:
using Quandl
using DataFrames
google = quandl("GOOG/NASDAQ_QQQ", format = "DataFrame")
date = google[1]
dt_str = Array(Any,length(date))
for i=1:length(date)
dt_str[i] = string(date[i]);
end
price = google[5]
using Gadfly
set_default_plot_size(20cm, 10cm)
p1 = plot(x=dt_str, y=price,
Geom.point,
Geom.smooth(method=:lm),
Guide.xticks(ticks=[1:25]),
Guide.yticks(ticks=[1:25]),
Guide.xlabel("Date"),
Guide.ylabel("Price"),
Guide.title("Google: Close Price"))
LoadError: PyError (:PyObject_Call) TypeError(u'There is no Line2D property "y"',) File "C:\Anaconda2\lib\site-packages\matplotlib\pyplot.py", line 3154, in plot ret = ax.plot(*args, **kwargs) File "C:\Anaconda2\lib\site-packages\matplotlib\__init__.py", line 1811, in inner return func(ax, *args, **kwargs) File "C:\Anaconda2\lib\site-packages\matplotlib\axes\_axes.py", line 1424, in plot for line in self._get_lines(*args, **kwargs): File "C:\Anaconda2\lib\site-packages\matplotlib\axes\_base.py", line 395, in _grab_next_args for seg in self._plot_args(remaining[:isplit], kwargs): File "C:\Anaconda2\lib\site-packages\matplotlib\axes\_base.py", line 374, in _plot_args seg = func(x[:, j % ncx], y[:, j % ncy], kw, kwargs) File "C:\Anaconda2\lib\site-packages\matplotlib\axes\_base.py", line 281, in _makeline self.set_lineprops(seg, **kwargs) File "C:\Anaconda2\lib\site-packages\matplotlib\axes\_base.py", line 189, in set_lineprops line.set(**kwargs) File "C:\Anaconda2\lib\site-packages\matplotlib\artist.py", line 936, in set (self.__class__.__name__, k)) while loading In[64], in expression starting on line 1 in getindex at C:\Users\yburkitbayev\.julia\v0.4\PyCall\src\PyCall.jl:239
答案 0 :(得分:1)
PyError的存在意味着我执行此示例的会话在加载Gadfly之前加载了PyPlot。 PyPlot和Gadfly都导出绘图函数,因此在加载了PyPlot和Gadfly的会话中使用plot需要使用包名称来限定函数名称(例如PyPlot.plot或Gadfly.plot)。
在尚未加载PyPlot的会话中执行您的示例,但加载了Gadfly,会生成一个Gadfly图,而不显示帖子中提供的错误消息。