在 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/