# Plots.jl how to create a heat map from several curves

**URL:** <https://discourse.julialang.org/t/plots-jl-how-to-create-a-heat-map-from-several-curves/47683>\
**Category:** General Usage\
**Tags:** package, plotting\
**Created:** [October 3, 2020, 6:41am UTC](https://discourse.julialang.org/t/plots-jl-how-to-create-a-heat-map-from-several-curves/47683 "2020-10-03T06:41:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![a\_garval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/a_garval/32/18371_2.png) [@a\_garval](https://discourse.julialang.org/u/a_garval)\
**Post date:** [October 3, 2020, 6:41am UTC](https://discourse.julialang.org/t/plots-jl-how-to-create-a-heat-map-from-several-curves/47683/1 "2020-10-03T06:41:39Z")

</div>

So I have about 100 different curves and I’d like to create a heatmap from them. These curves each represent possible solutions to a differential equation and I’d like to create a sort of density plot from them so that in every point in time I can have a 2D smooth kernel histogram. I append an example I made in python. It was done creating a histogram at every point in time but it was really slow and not too visually appealing

![Captura de pantalla_2020-10-03_01-39-34](https://global.discourse-cdn.com/julialang/original/3X/0/8/08db9dad7b1336d61515e57737cffedbfaea089c.png)

![Captura de pantalla_2020-10-03_01-39-47](https://global.discourse-cdn.com/julialang/original/3X/7/1/711a7af05852c49d6ba341046c35e01b7bd66a50.png)

Any help will be greatly appreciated!

EDIT: To be more clear. I generate a 100 parameters “p” to a differential equation y’ = f(t, p)and integrate using those parameters and the same set of initial conditions to generate 100 solutions. What I’d like is a plot where t is on the horizontal axis, y on the vertical one and the colour intensity is given by how many of those 100 solutions pass through the point (t, y)

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 3, 2020, 1:07pm UTC](https://discourse.julialang.org/t/plots-jl-how-to-create-a-heat-map-from-several-curves/47683/2 "2020-10-03T13:07:41Z")

</div>

It’s not clear to me what you want to achieve, from what kind of input. Usually a [heatmap](https://en.wikipedia.org/wiki/Heat_map) is not a series of curves. Please clarify, and provide an MWE generating the data.

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757/):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![sswatson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sswatson/32/5135_2.png) [@sswatson](https://discourse.julialang.org/u/sswatson)\
**Post date:** [October 3, 2020, 1:48pm UTC](https://discourse.julialang.org/t/plots-jl-how-to-create-a-heat-map-from-several-curves/47683/3 "2020-10-03T13:48:01Z")

</div>

Are you saying you want a plot with time on the horizontal axis, the curve index on the vertical axis, and the curve’s height represented by color?

If so, just concatenate the vectors representing the curves to make a 2D array, and then `heatmap` that array. A surface plot might also be a reasonable choice, given the shapes of those curves.

---

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [October 3, 2020, 1:56pm UTC](https://discourse.julialang.org/t/plots-jl-how-to-create-a-heat-map-from-several-curves/47683/4 "2020-10-03T13:56:52Z")

</div>

You can just plot all your curves using a transparent color, otherwise you have to do your histogram, it should be faster in Julia.

---

<div class="post-metadata">

**Author:** ![a\_garval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/a_garval/32/18371_2.png) [@a\_garval](https://discourse.julialang.org/u/a_garval)\
**Post date:** [October 3, 2020, 3:40pm UTC](https://discourse.julialang.org/t/plots-jl-how-to-create-a-heat-map-from-several-curves/47683/5 "2020-10-03T15:40:48Z")

</div>

It’s more like time is in the horizontal axis, f(t) is the vertical axis and the height is given by how many curves pass through a point (t, f(t)). I’ll try to generate a MWE if it’s not that clear but I might not be able to do it

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [October 3, 2020, 4:25pm UTC](https://discourse.julialang.org/t/plots-jl-how-to-create-a-heat-map-from-several-curves/47683/6 "2020-10-03T16:25:05Z")

</div>

With GMT.jl you would prepare a Mx3 array with `t, f(t), curve_value_at(t, f(t))` and compute a grid with counting at each cell, Something like

```julia
G = blocmean(data_matrix, region=(0,t_max,0,ft_max), inc=cell_width, npts=:n);
imshow(G, fmt=:png)

```

---

<div class="post-metadata">

**Author:** ![theogf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theogf/32/1987_2.png) [@theogf](https://discourse.julialang.org/u/theogf)\
**Post date:** [October 3, 2020, 4:56pm UTC](https://discourse.julialang.org/t/plots-jl-how-to-create-a-heat-map-from-several-curves/47683/7 "2020-10-03T16:56:33Z")

</div>

Given that you have a lot of points, a `contourf` sounds more adapted ?  
Assuming you have `p(x,t)` for each `x` and `t` create a matrix out of it and give `x` and `t` for horizontal and vertical axis.  
Something like

```julia
using Distributions, Plots
x = range(-5, 5, length = 100);
s = range(0.01, 3.0, length = 100);
Z = reduce(hcat, [pdf(Normal(0, exp(sig)), x) for sig in s])
contourf(x, s, Z', xlabel = "x", ylabel = "sig")

```

![varyingsigma](https://global.discourse-cdn.com/julialang/original/3X/4/d/4dbc45ed9211af87dc0c3b55e9fd29225a804a75.png)  
Note that you can still replace `contourf` by `heatmap` to get more or less the same result  
 ![varyingsigma](https://global.discourse-cdn.com/julialang/original/3X/3/d/3dcd7c292fc1aeecd6ae6cfb977fb0fef52f82b3.png)
