# Gadfly: adding line-styles to the plot legend

**URL:** <https://discourse.julialang.org/t/gadfly-adding-line-styles-to-the-plot-legend/29188>\
**Category:** General Usage\
**Created:** [September 26, 2019, 10:54am UTC](https://discourse.julialang.org/t/gadfly-adding-line-styles-to-the-plot-legend/29188 "2019-09-26T10:54:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)\
**Post date:** [September 26, 2019, 10:54am UTC](https://discourse.julialang.org/t/gadfly-adding-line-styles-to-the-plot-legend/29188/1 "2019-09-26T10:54:37Z")

</div>

Dear community,

I want to create a plot with several lines that have different line-styles (e.g., solid, dashed, dotted,…), and to add these styles to the legend of the plot (to fit for a black-white publication). Is there any built-in option for that in the meanwhile, or a better work around than [this](https://discourse.julialang.org/t/gadfly-plot-with-several-graphs-suitable-for-publications/3718) one?

Thank you in advance and kind regards,  
Michael

---

<div class="post-metadata">

**Author:** ![lanaperisa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lanaperisa/32/4555_2.png) [@lanaperisa](https://discourse.julialang.org/u/lanaperisa)\
**Post date:** [September 26, 2019, 11:17am UTC](https://discourse.julialang.org/t/gadfly-adding-line-styles-to-the-plot-legend/29188/2 "2019-09-26T11:17:23Z")

</div>

Hi, I found that PyPlot is actually better for this purpose, here’s my code:

```julia

    subplots()
    xlabel("x",fontsize=14)
    title("Title",fontsize=14)
    yscale("log")
    grid("on")
    ylabel("Time (s)",fontsize=14)
    plot(X,time1,label="Label1",color="orange",linewidth=3)
    plot(X,time2,label="Label2",color="green",linestyle="--",linewidth=3)
    plot(X,time3,label="Label3",color="blue",linestyle="-.",linewidth=3)
    legend()
    xticks(X)
    ax=gca()
    ax.set_xlim([X[1],X[end]])
    ax.legend(loc="upper left")

```

Hope it helps.

---

<div class="post-metadata">

**Author:** ![kdyrhage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kdyrhage/32/2326_2.png) [@kdyrhage](https://discourse.julialang.org/u/kdyrhage)\
**Post date:** [September 26, 2019, 11:29am UTC](https://discourse.julialang.org/t/gadfly-adding-line-styles-to-the-plot-legend/29188/3 "2019-09-26T11:29:17Z")

</div>

I haven’t used Gadfly, but with Plots you can do this:

```julia
using Plots
plot(rand(10, 5),
     line = [:solid :dash :dot :dashdot :dashdotdot],
     color = :black)

```

---

<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:** [September 26, 2019, 11:39am UTC](https://discourse.julialang.org/t/gadfly-adding-line-styles-to-the-plot-legend/29188/4 "2019-09-26T11:39:33Z")

</div>

For Gadfly, there’s examples of the `linestyle` aesthetic [here](http://gadflyjl.org/dev/gallery/scales/#%5BScale.linestyle_discrete%5D(@ref)-1).  
In the [tutorial](http://gadflyjl.org/stable/tutorial/#Discrete-Scales-1), `Guide.linekey` is marked as to be done.

---

<div class="post-metadata">

**Author:** ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)\
**Post date:** [September 26, 2019, 2:36pm UTC](https://discourse.julialang.org/t/gadfly-adding-line-styles-to-the-plot-legend/29188/5 "2019-09-26T14:36:14Z")

</div>

Thank you all. I gave a try using Plots together with PyPlot as backend, and this seems to work fine for my purposes.
