arrays - 如何在 Julia 0.6 中转置字符串向量(以便绘制多个图例)?

标签 arrays plot julia

在 Julia 0.5 中你可以这样写:

using DataFrames, Plots, StatPlots
df = DataFrame(
    fruit = ["orange","orange","orange","orange","apple","apple","apple","apple"],
    year = [2010,2011,2012,2013,2010,2011,2012,2013],
    production = [120,150,170,160,100,130,165,158],
    consumption = [70,90,100,95, 80,95,110,120]
)
plotlyjs()
mycolours = [:green :orange]
legend1 = sort(unique(df[:fruit]))
legend2 = legend1'
fruits_plot = plot(df, :year, :production, group=:fruit, linestyle = :solid, linewidth=3, label = ("Production of " * legend2), color=mycolours)

其中 legend1 是一个 2 元素 DataArrays.DataArray{String,1}legend2 是一个 1×2 DataArrays .DataArray{String,2}.

现在,在 julia 0.6 中 legend2 = legend1' 不再起作用。您可以改为使用 legend2 = reshape(legend1, (1, :)),但这会产生相当晦涩的 1×2 Base.ReshapeArray{String,2,DataArrays.DataArray{String ,1},Tuple{}}plot() 调用中不被接受。

因此,在 julia 0.6 中,可以通过任何方式从 2 元素 DataArrays.DataArray{String,1} 生成 1×2 DataArrays.DataArray{String,2} ?

最佳答案

再说一次,在 SO 上发帖有帮助..;-)

我终于知道我可以获得预期字符串连接的图:

fruits_plot = plot(df, :year, :production, group=:fruit, linestyle = :solid, linewidth=3, label= reshape("Production of " * sort(unique(df[:fruit])),(1,:)), color=mycolours)

关于arrays - 如何在 Julia 0.6 中转置字符串向量(以便绘制多个图例)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45183643/

相关文章:

没有迭代的Javascript数组空检查

matlab - 直方图产生的值低于预期

r - 图例将 bquote 与向量变量一起使用

r - 更改箭头的箭头()

julia - 在 Julia 中插值时如何格式化字符串?

ios - swift 展开问题

arrays - 数据结构面试: find max number in array

testing - 是否可以在 Julia 中组织健全性检查,以便在加载包时轻松编译它们?

julia - 使用 Plots.jl 高效地动画子图

java - 从另一个类访问带有数组的方法