matplotlib - How to plot 4-D data embedded in a dataframe in Julia using a subplots approach? -
i have julia dataframe first 4 columns dimensions , 5th 1 contains actual data.
i plot using subplots approach 2 main plot axis concern first 2 dimensions , each subplot contour plot on remaining 2 dimensions.
i there above code:
using dataframes,plots # plotlyjs() # doesn't work plotlyjs backend pyplot() x = [1,2,3,4] y = [0.1,0.15,0.2] = [2,4,6,8,10,12,14] j = [10,20,30,40,50,60] df = dataframe(x=int64[], y=float64[], i=float64[], j=float64[], v=float64[] ) [push!(df,[x,y,i,j,(5*x+20*y+2)*(0.2*i^2+0.5*j^2+3*i*j+2*i^2*j+1)]) x in x, y in y, in i, j in j] minvalue = minimum(df[:v]) maxvalue = maximum(df[:v]) function todict(df, dimcols, valuecol) toreturn = dict() r in eachrow(df) keyvalues = [] [push!(keyvalues,r[d]) d in dimcols] toreturn[(keyvalues...)] = r[valuecol] end return toreturn end dict = todict(df, [:x,:y,:i,:j], :v ) m = [dict[(x,y,i,j)] j in j, in i, y in y, x in x ] yl = length(y) xl = length(x) plot(contour(m[:,:,3,1], ylabel="y = $(string(y[3]))", zlims=(minvalue,maxvalue)), contour(m[:,:,3,2]), contour(m[:,:,3,3]), contour(m[:,:,3,4]), contour(m[:,:,2,1], ylabel="y = $(string(y[2]))", zlims=(minvalue,maxvalue)), contour(m[:,:,2,2]), contour(m[:,:,2,3]), contour(m[:,:,2,4]), contour(m[:,:,1,1], ylabel="y = $(string(y[1]))", xlabel="x = $(string(x[1]))"), contour(m[:,:,1,2], xlabel="x = $(string(x[2]))"), contour(m[:,:,1,3], xlabel="x = $(string(x[3]))"), contour(m[:,:,3,4], xlabel="x = $(string(x[4]))"), layout=(yl,xl) )
i remain following concerns:
- how automatize creation of each subplot in subplot call ? need write macro ?
- i each subplot have same limits in z axis, zlims seems not work. zlims not yet supported ?
- how hide legend on z axis on each subplot , plot instead apart (best on right side of main/total plot) ?
edit: first point don't need macro, can create subplots in loop, add them in array , pass array plot() call using ellipsis operator:
plots = [] y in length(y):-1:1 x in 1:length(x) xlabel = y == 1 ? "x = $(string(x[x]))" : "" ylabel = x==1 ? "y = $(string(y[y]))" : "" println("$y - $x") plot = contour(i,j,m[:,:,y,x], xlabel=xlabel, ylabel=ylabel, zlims=(minvalue,maxvalue)) push!(plots,plot) end end plot(plots..., layout=(yl,xl))
Comments
Post a Comment