我在Julia绘图时遇到问题。将excel文件上传到数据框并打印后,我收到错误:"无法将数据框转换为用于打印的系列数据"。参考触发错误的最简单代码:
using Plots, XLSX, DataFrames
Colbalt = DataFrame(XLSX.readtable("/Users/jjtan/Downloads/statisticsExport.xlsx", "Sheet 1"))
plot(Colbalt, x = :Year, y = :Total)
堆栈跟踪:
ERROR: Cannot convert DataFrame to series data for plotting
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:35
[2] _prepare_series_data(x::DataFrame)
@ RecipesPipeline ~/.julia/packages/RecipesPipeline/F2mWY/src/series.jl:8
[3] _series_data_vector(x::DataFrame, plotattributes::Dict{Symbol, Any})
@ RecipesPipeline ~/.julia/packages/RecipesPipeline/F2mWY/src/series.jl:27
[4] macro expansion
@ ~/.julia/packages/RecipesPipeline/F2mWY/src/series.jl:127 [inlined]
[5] apply_recipe(plotattributes::AbstractDict{Symbol, Any}, #unused#::Type{RecipesPipeline.SliceIt}, x::Any, y::Any, z::Any)
@ RecipesPipeline ~/.julia/packages/RecipesBase/apcHH/src/RecipesBase.jl:290
[6] _process_userrecipes!(plt::Any, plotattributes::Any, args::Any)
@ RecipesPipeline ~/.julia/packages/RecipesPipeline/F2mWY/src/user_recipe.jl:36
[7] recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)
@ RecipesPipeline ~/.julia/packages/RecipesPipeline/F2mWY/src/RecipesPipeline.jl:70
[8] _plot!(plt::Plots.Plot, plotattributes::Any, args::Any)
@ Plots ~/.julia/packages/Plots/W75kY/src/plot.jl:232
[9] #plot#149
@ ~/.julia/packages/Plots/W75kY/src/plot.jl:107 [inlined]
[10] top-level scope
@ ~/Documents/Research/Grants/CDFA-ANALYSIS/##Packgaes.jl:9
您在哪里找到该语法?正如错误所说,不能直接绘制DataFrame
对象。相反,将要绘制为矢量的列传递:
plot(Colbalt.Year, Colbalt.Total)
Plots
的StatsPlots
扩展为绘制数据帧提供了一些方便的宏,以下是Readme:中的一些示例
using DataFrames
df = DataFrame(a = 1:10, b = 10 .* rand(10), c = 10 .* rand(10))
@df df plot(:a, [:b :c], colour = [:red :blue])
@df df scatter(:a, :b, markersize = 4 .* log.(:c .+ 0.1))