# Constant dash density in Plots.jl

**URL:** <https://discourse.julialang.org/t/constant-dash-density-in-plots-jl/34087>\
**Category:** General Usage\
**Tags:** plotting, plots\
**Created:** [February 2, 2020, 4:05pm UTC](https://discourse.julialang.org/t/constant-dash-density-in-plots-jl/34087 "2020-02-02T16:05:48Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [February 2, 2020, 4:05pm UTC](https://discourse.julialang.org/t/constant-dash-density-in-plots-jl/34087/1 "2020-02-02T16:05:48Z")

</div>

Hi,

I have a plot where I want to display some dash. But as the density of points increases, the dashes merge and become a straight line. This can be seen on the left of the plot near x=0.02.

Does anybody knows how to avoid this behavior?

Thank you for your help,

 ![Screen Shot 2020-02-02 at 17.02.26](https://global.discourse-cdn.com/julialang/original/3X/5/b/5b84c1df0291ac968ef73604b30384d6132f50a5.png)

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [February 2, 2020, 5:58pm UTC](https://discourse.julialang.org/t/constant-dash-density-in-plots-jl/34087/2 "2020-02-02T17:58:23Z")

</div>

Use something like Interpolations.jl and sample your functions at regular intervals?

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [February 2, 2020, 7:51pm UTC](https://discourse.julialang.org/t/constant-dash-density-in-plots-jl/34087/3 "2020-02-02T19:51:08Z")

</div>

Indeed, if there is no built in solution in Plots, that would be a good way!

Thank you

---

<div class="post-metadata">

**Author:** ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)\
**Post date:** [February 2, 2020, 8:17pm UTC](https://discourse.julialang.org/t/constant-dash-density-in-plots-jl/34087/4 "2020-02-02T20:17:28Z")

</div>

Which `Plots` backend are you using? Shouldn’t happen with `gr()`:

```julia
using GR
x = 1:100
setlinetype(2)
plot(log.(x),x)

```

 ![Screen Shot 2020-02-02 at 21.16.52](https://global.discourse-cdn.com/julialang/original/3X/2/e/2ef52c7449e1e0547818c382ea8f6a015aec8be4.png)

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [February 2, 2020, 9:01pm UTC](https://discourse.julialang.org/t/constant-dash-density-in-plots-jl/34087/5 "2020-02-02T21:01:30Z")

</div>

It is GR…here is a MWE:

```julia
N = 5
x = 1:(2N)
ls = vcat([:solid for _=1:N], [:dash for _=1:N])
plot(log.(x),x; linestyle = ls)

```

N = 5:

 ![Screen Shot 2020-02-02 at 22.00.28](https://global.discourse-cdn.com/julialang/original/3X/d/d/ddcef753824181562a57f175149832bdca88fec3.png)

N=50

 ![Screen Shot 2020-02-02 at 22.00.48](https://global.discourse-cdn.com/julialang/original/3X/4/3/43a16a92d056187f24cf0a2e9df84eee3c18ee5b.png)

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [February 3, 2020, 8:29am UTC](https://discourse.julialang.org/t/constant-dash-density-in-plots-jl/34087/6 "2020-02-03T08:29:16Z")

</div>

Note that I am using broadcasting of arguments as in this [discourse post](https://discourse.julialang.org/t/plots-jl-attributes-can-be-broadcasted-changing-linestyle-for-example/19559)

---

<div class="post-metadata">

**Author:** ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)\
**Post date:** [February 3, 2020, 12:18pm UTC](https://discourse.julialang.org/t/constant-dash-density-in-plots-jl/34087/7 "2020-02-03T12:18:11Z")

</div>

Unfortunately I still cannot see where the problem is in `GR`, especially since `PyPlot` and `PlotlyJS` give exactly the same results …

What should the plot look like after repeated overdrawing?

Do you probably want the internal dash offset be the same?

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [February 3, 2020, 12:31pm UTC](https://discourse.julialang.org/t/constant-dash-density-in-plots-jl/34087/8 "2020-02-03T12:31:12Z")

</div>

> [@jheinen](#):
>
> What should the plot look like after repeated overdrawing?

I want the dash to be visible, constant density is maybe asking too much

---

<div class="post-metadata">

**Author:** ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)\
**Post date:** [February 3, 2020, 1:16pm UTC](https://discourse.julialang.org/t/constant-dash-density-in-plots-jl/34087/9 "2020-02-03T13:16:41Z")

</div>

This would mean drawing the dash pattern with the line and the (window) background color. In GR this is theoretically possible, but only via an internal (software) emulation.

Is this really what you want, or did I misunderstand the purpose?

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [February 3, 2020, 1:29pm UTC](https://discourse.julialang.org/t/constant-dash-density-in-plots-jl/34087/10 "2020-02-03T13:29:52Z")

</div>

> [@jheinen](#):
>
> Is this really what you want, or did I misunderstand the purpose?

I can reformulate to be sure. It is linked to this [post](https://discourse.julialang.org/t/plots-jl-attributes-can-be-broadcasted-changing-linestyle-for-example/19559).

I want to be able to draw curves and specify, with an argument, the linestyle of the points so as to be able to control which parts of the curve are continuous and which are dash. Additionally, I want the dashed part to be visible irrespective of the underlying point density.

---

<div class="post-metadata">

**Author:** ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)\
**Post date:** [February 3, 2020, 1:55pm UTC](https://discourse.julialang.org/t/constant-dash-density-in-plots-jl/34087/11 "2020-02-03T13:55:07Z")

</div>

Ok - I understand. But, IMO that’s a functionality that should be provided/implemented in `Plots.jl` - not in the backend code. The main reason is, that most underlying (low-level) systems would not support multiple line attributes within a path.

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [February 3, 2020, 2:23pm UTC](https://discourse.julialang.org/t/constant-dash-density-in-plots-jl/34087/12 "2020-02-03T14:23:12Z")

</div>

I agree. Note that I did not ask specifically for a GR solution. Thank you for your help

---

<div class="post-metadata">

**Author:** ![matthieu](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@matthieu](https://discourse.julialang.org/u/matthieu)\
**Post date:** [November 28, 2022, 9:41pm UTC](https://discourse.julialang.org/t/constant-dash-density-in-plots-jl/34087/13 "2022-11-28T21:41:46Z")

</div>

I encountered this issue too and I do think it should be solved.
