# Plot different length data together in Gadfly

**URL:** <https://discourse.julialang.org/t/plot-different-length-data-together-in-gadfly/77036>\
**Category:** Visualization\
**Tags:** gadfly\
**Created:** [February 24, 2022, 7:02pm UTC](https://discourse.julialang.org/t/plot-different-length-data-together-in-gadfly/77036 "2022-02-24T19:02:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [February 24, 2022, 7:02pm UTC](https://discourse.julialang.org/t/plot-different-length-data-together-in-gadfly/77036/1 "2022-02-24T19:02:54Z")

</div>

I am struggling to plot two different (x,y) lines together with a single `plot` command and the default color palette, since apparently I can’t give the layers `label = "Data Label"` like in Plots.jl. What is the best way to do this? Is it easier in Makie or VegaLite?

```julia
using Gadfly
x1=0:0.1:5
x2=0:0.5:5
y1=sin.(x1)
y2=sin.(x2).+0.2
layer1 = layer(x=x1, y=y1, Geom.line, color=[1])
layer2 = layer(x=x2, y=y2, Geom.line, color=[2])
plot(layer1,
     layer2,
     style(line_width=2pt),
     Guide.xlabel("x"),
     Guide.ylabel("y"),
     Guide.manual_color_key("",["Theory","Data"]))

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/8/b8f3561b056f289d1d2600e4601e1d37d33fb022.png)  
[Similar Discourse Post](https://discourse.julialang.org/t/gadfly-and-controling-colors-and-label/59290)

---

<div class="post-metadata">

**Author:** ![bjarthur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bjarthur/32/9638_2.png) [@bjarthur](https://discourse.julialang.org/u/bjarthur)\
**Post date:** [February 24, 2022, 7:44pm UTC](https://discourse.julialang.org/t/plot-different-length-data-together-in-gadfly/77036/2 "2022-02-24T19:44:52Z")

</div>

```julia
using DataFrames

df = DataFrame(x=[x1; x2],
               y=[y1; y2],
               kind=[repeat(["Theory"], length(x1));
                     repeat(["Data"], length(x2))])

plot(df, x=:x, y=:y, color=:kind, Geom.line)

```

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [February 24, 2022, 10:03pm UTC](https://discourse.julialang.org/t/plot-different-length-data-together-in-gadfly/77036/3 "2022-02-24T22:03:51Z")

</div>

The top plot can be done like this too:

```julia
layer1 = layer(x=x1, y=y1, Geom.line, color=["Theory"])
layer2 = layer(x=x2, y=y2, Geom.line, color=["Data"])
p = plot(layer1, layer2, style(line_width=2pt),
     Guide.xlabel("x"), Guide.ylabel("y"), Guide.colorkey(""))

```

![plot01](https://global.discourse-cdn.com/julialang/original/3X/3/9/391a36b22604bce7585bbee7fb41c351d069ebbe.png)

---

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [February 25, 2022, 4:47pm UTC](https://discourse.julialang.org/t/plot-different-length-data-together-in-gadfly/77036/4 "2022-02-25T16:47:04Z")

</div>

# Fontconfig package (required for saving) breaks the plot.

I can reproduce the plot above.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/2/7/273ef785014cd572d6ac9969d8e5efc1d45a3c23.png)

```julia-auto
add Cairo, Fontconfig
p = plot(layer1, layer2, style(line_width=2pt), Guide.xlabel("x"), Guide.ylabel("y"), Guide.colorkey(""))

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/f/1/f1b84cb70b8798d6e31d25e759a72c4e9e20d14e.png)

```julia-auto
draw(PNG("Test.png", 6inch, 4inch), p)

```

 ![Test](https://global.discourse-cdn.com/julialang/original/3X/c/6/c61908eb232860e357474a8b48adb32d73db86c6.png)

---

<div class="post-metadata">

**Author:** ![bjarthur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bjarthur/32/9638_2.png) [@bjarthur](https://discourse.julialang.org/u/bjarthur)\
**Post date:** [February 25, 2022, 5:06pm UTC](https://discourse.julialang.org/t/plot-different-length-data-together-in-gadfly/77036/5 "2022-02-25T17:06:35Z")

</div>

> [@Nathan\_Boyer](#):
>
> `draw(PNG("Test.png", 6inch, 4inch), p)`

i can’t reproduce. here’s my PNG:

![Test](https://global.discourse-cdn.com/julialang/original/3X/2/7/27ca7cefbe5358843d4e9e8e8370ff838865442c.png)

---

<div class="post-metadata">

**Author:** ![bjarthur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bjarthur/32/9638_2.png) [@bjarthur](https://discourse.julialang.org/u/bjarthur)\
**Post date:** [February 25, 2022, 5:08pm UTC](https://discourse.julialang.org/t/plot-different-length-data-together-in-gadfly/77036/6 "2022-02-25T17:08:07Z")

</div>

what version of Gadfly, Julia, etc. and what OS are you using?

---

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [February 25, 2022, 5:19pm UTC](https://discourse.julialang.org/t/plot-different-length-data-together-in-gadfly/77036/7 "2022-02-25T17:19:12Z")

</div>

I get the same behavior using Pluto, WSL terminal, and VSCode for Windows.  
Newest version for all:  
Julia: 1.7.2  
Gadfly: 1.3.4  
Cairo: 1.0.5  
Fontconfig: 0.4.0

 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/1/111bd1e7f8a4de41e0d34875f1b96b7cb2d4f395.png)

---

<div class="post-metadata">

**Author:** ![monty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/monty/32/44234_2.png) [@monty](https://discourse.julialang.org/u/monty)\
**Post date:** [June 17, 2022, 4:10pm UTC](https://discourse.julialang.org/t/plot-different-length-data-together-in-gadfly/77036/8 "2022-06-17T16:10:17Z")

</div>

@bjarthur I hope this gets resolved. I am using the same versions and I have the same problem.

---

<div class="post-metadata">

**Author:** ![monty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/monty/32/44234_2.png) [@monty](https://discourse.julialang.org/u/monty)\
**Post date:** [June 22, 2022, 12:33pm UTC](https://discourse.julialang.org/t/plot-different-length-data-together-in-gadfly/77036/9 "2022-06-22T12:33:00Z")

</div>

@bjarthur any updates on this major problem with plotting gadfly figures!?
