# How use Dataframes columns as a z axis for 3d plot

**URL:** <https://discourse.julialang.org/t/how-use-dataframes-columns-as-a-z-axis-for-3d-plot/64536>\
**Category:** New to Julia\
**Tags:** plotting\
**Created:** [July 12, 2021, 9:32pm UTC](https://discourse.julialang.org/t/how-use-dataframes-columns-as-a-z-axis-for-3d-plot/64536 "2021-07-12T21:32:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rodolforbcoutinho](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rodolforbcoutinho/32/27067_2.png) [@rodolforbcoutinho](https://discourse.julialang.org/u/rodolforbcoutinho)\
**Post date:** [July 12, 2021, 9:32pm UTC](https://discourse.julialang.org/t/how-use-dataframes-columns-as-a-z-axis-for-3d-plot/64536/1 "2021-07-12T21:32:35Z")

</div>

Hello,  
I have a TimeArray in which the first column is the timestamp and all other columns are related to energy cost for a load over time. I have about 100 other columns. I’m trying to plot the other columns as a z axis, so I have something like: x\_axis as TimeStamp, y\_axis as values, z\_axis as columns names/labels. I have named all data columns as [“c1”, “c2” etc].

Just don’t have idea if its possible or how to do this.

Anyone could help on this?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [July 12, 2021, 10:17pm UTC](https://discourse.julialang.org/t/how-use-dataframes-columns-as-a-z-axis-for-3d-plot/64536/2 "2021-07-12T22:17:35Z")

</div>

DataFrame columns are just vectors. So nothing about DataFrames is needed here. Maybe [this example](https://docs.juliaplots.org/latest/generated/gr/#gr-ref43) in Plots.jl can help. Instead of `x`, `y`, and `z`, use the columns you want.

---

<div class="post-metadata">

**Author:** ![rodolforbcoutinho](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rodolforbcoutinho/32/27067_2.png) [@rodolforbcoutinho](https://discourse.julialang.org/u/rodolforbcoutinho)\
**Post date:** [July 12, 2021, 11:01pm UTC](https://discourse.julialang.org/t/how-use-dataframes-columns-as-a-z-axis-for-3d-plot/64536/3 "2021-07-12T23:01:56Z")

</div>

![Comparativo gráficos](https://global.discourse-cdn.com/julialang/original/3X/d/e/de563723671bd658973af12134e5c7c67ae74d59.png)  
Hi, thanks for the answer. But I’m afraid its not what I’m looking for. Heatmap gave me the black graph on the right. I want something more like the left graph but in 3D and for all 121 columns.  
In the left graph i showed only 5 of them.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [July 13, 2021, 1:30am UTC](https://discourse.julialang.org/t/how-use-dataframes-columns-as-a-z-axis-for-3d-plot/64536/4 "2021-07-13T01:30:08Z")

</div>

You mean like this? [https://www.r-graph-gallery.com/294-basic-ridgeline-plot.html](https://www.r-graph-gallery.com/294-basic-ridgeline-plot.html)

---

<div class="post-metadata">

**Author:** ![rodolforbcoutinho](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rodolforbcoutinho/32/27067_2.png) [@rodolforbcoutinho](https://discourse.julialang.org/u/rodolforbcoutinho)\
**Post date:** [July 15, 2021, 3:26pm UTC](https://discourse.julialang.org/t/how-use-dataframes-columns-as-a-z-axis-for-3d-plot/64536/5 "2021-07-15T15:26:44Z")

</div>

visualy this 3D graph would do the job! But not using the density function. Data I have isn’t a distribution or related. I tried for the last 2 days to draw this graph but its not working.

I’m trying to plot now with CairoMakie.jl Any other suggestion?

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [July 15, 2021, 4:19pm UTC](https://discourse.julialang.org/t/how-use-dataframes-columns-as-a-z-axis-for-3d-plot/64536/7 "2021-07-15T16:19:02Z")

</div>

I don’t think I’ve ever seen one of those plots that aren’t a density plots, in R or Julia. The best option might be to abandon the ridge plot and just do a traditional line plot with different colors.

---

<div class="post-metadata">

**Author:** ![Derek\_Vetsch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/derek_vetsch/32/8552_2.png) [@Derek\_Vetsch](https://discourse.julialang.org/u/Derek_Vetsch)\
**Post date:** [July 15, 2021, 4:25pm UTC](https://discourse.julialang.org/t/how-use-dataframes-columns-as-a-z-axis-for-3d-plot/64536/8 "2021-07-15T16:25:09Z")

</div>

> so I have something like: x\_axis as TimeStamp, y\_axis as values, z\_axis as columns names/labels

Can you provide an example of your data? I’m not sure I understand what you are hoping to portray on the Z-Axis.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [July 15, 2021, 4:43pm UTC](https://discourse.julialang.org/t/how-use-dataframes-columns-as-a-z-axis-for-3d-plot/64536/9 "2021-07-15T16:43:09Z")

</div>

Would successive 3D line plots be adequate?  
 ![Plot3d_DataFrame](https://global.discourse-cdn.com/julialang/original/3X/5/2/52872f407c7c00e332846d2d3dad8625484c3107.png)

```julia
using Plots, Dates, DataFrames

dts = today():Year(1):today()+Year(20)
m = length(dts)
n = 100
vs = rand(m,n) .+ vec(1:n)' .- n÷2
df = DataFrame([dts vs], :auto)
p = plot(legend=false, xlabel="Date",ylabel="curve#",zlabel="values")
[plot!(df[:,1], fill(i,m), df[:,i+1]) for i in 1:n]
display(p)

```

---

<div class="post-metadata">

**Author:** ![rodolforbcoutinho](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rodolforbcoutinho/32/27067_2.png) [@rodolforbcoutinho](https://discourse.julialang.org/u/rodolforbcoutinho)\
**Post date:** [July 15, 2021, 7:02pm UTC](https://discourse.julialang.org/t/how-use-dataframes-columns-as-a-z-axis-for-3d-plot/64536/10 "2021-07-15T19:02:00Z")

</div>

This code worked fine.

```julia
function plot_curvas_custo(custo::TimeArray)
	m = length(timestamp(custo))
	n = length(colnames(custo))
	df = values(custo)
	p = plot(legend=false, xlabel="Horário",ylabel="#Curva",zlabel="R\$")
	[plot!(timestamp(custo), fill(i,m), df[:,i]) for i in 1:div(n,10):n]
	plot(p)
end

```

 ![Gráficos 2](https://global.discourse-cdn.com/julialang/original/3X/6/0/60e5c38e1014934d30e9d87f9b69479cc04a4ec2.png)  
Thanks to all that reply!!!
