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

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

问题描述

I am learning the Julia from the coursera

using DelimitedFiles
EVDdata = DelimitedFiles.readdlm("wikipediaEVDdatesconverted.csv", ',')

# extract the data
epidays = EVDdata[:,1]
EVDcasesbycountry = EVDdata[:, [4, 6, 8]]

# load Plots and plot them
using Plots
gr()
plot(epidays, EVDcasesbycountry)

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.

Or am I missing something else.

解决方案

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.

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)

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])

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天全站免登陆