无法将Array {Any,2}转换为序列数据以进行绘图 [英] Cannot convert Array{Any,2} to series data for plotting

查看:40
本文介绍了无法将Array {Any,2}转换为序列数据以进行绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从

我收到错误消息无法将Array {Any,2}转换为用于绘图的系列数据但是在那门课程中,讲师成功地绘制了数据.我要去哪里错了?

I am getting the error message Cannot convert Array{Any,2} to series data for plotting but in that course the lecturer successfully plots the data. where I am going wrong?

我搜索有关错误的信息,最终我得到了一些将字符串解析为整数的调用.由于数据集可能包含字符串值.

I search about the error where I end up something call parsing the string into an integer. As the data set may contain string values.

还是我想念其他东西.

推荐答案

很难确定Coursera中发生了什么,因为尚不清楚视频正在使用哪个版本的Plots和DataFrames.

It's a bit hard to tell what's going on in Coursera, as it's not clear what versions of Plots and DataFrames the video is using.

但是,您看到的错误告诉您二维数组(即矩阵)无法转换为用于绘图的单个序列.这是因为 plot 应该用两个向量调用,一个用于x,一个用于y值:

The error you're seeing however is telling you that a 2-dimensional Array (i.e. a matrix) can't be converted to a single series for plotting. This is because plot is supposed to be called with two vectors, one for x and one for y values:

plot(epidays, EVData[:, 4])

您可以在一个循环中绘制多个列:

You can plot multiple columns in a loop:

p = plot()
for c in eachcol(EVData[:, [4, 6, 8]])
    plot!(p, epidays, c)
end
display(p)

还有 StatsPlots.jl ,它扩展了标准的 Plots.jl 包,用于经常需要的数据科学-y"绘图功能.在这种情况下,您可以使用 @df 宏来绘制DataFrame.只需引用自述文件中的示例之一:

There is also StatsPlots.jl, which extend the standard Plots.jl package for frequently needed "data science-y" plotting functions. In this case you could use the @df macro for plotting DataFrames; just quoting one of the examples in the Readme:

using DataFrames, IndexedTables
df = DataFrame(a = 1:10, b = 10 .* rand(10), c = 10 .* rand(10))
@df df plot(:a, [:b :c], colour = [:red :blue])

最后,在Julia中还有更多受图形语法启发的绘图程序包,这些程序包着重于绘制DataFrames,例如纯朱莉娅 Gadfly.jl 或VegaLite包装器 VegaLite.jl

Finally, there are some more grammar-of-graphics inspired plotting packages in Julia which are focused on plotting DataFrames, e.g. the pure-Julia Gadfly.jl, or the VegaLite wrapper VegaLite.jl

这篇关于无法将Array {Any,2}转换为序列数据以进行绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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