# Plot several shapes as part of a single series using Plots.jl

**URL:** <https://discourse.julialang.org/t/plot-several-shapes-as-part-of-a-single-series-using-plots-jl/132878>\
**Category:** Visualization\
**Tags:** plots\
**Created:** [October 4, 2025, 9:25pm UTC](https://discourse.julialang.org/t/plot-several-shapes-as-part-of-a-single-series-using-plots-jl/132878 "2025-10-04T21:25:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alan/32/15970_2.png) [@alan](https://discourse.julialang.org/u/alan)\
**Post date:** [October 4, 2025, 9:25pm UTC](https://discourse.julialang.org/t/plot-several-shapes-as-part-of-a-single-series-using-plots-jl/132878/1 "2025-10-04T21:25:06Z")

</div>

I’m trying to plot several rectangles of the same color, and I want them to show up as a single entry in the legend. But my code produces a separate legend entry for each rectangle. Suggestions?

```julia-auto
using Plots

function rectangle(w, h, x, y; voffset=0)
    y -= 0.5*h
    if voffset != 0
        y += voffset*h
    end
    Shape(x .+ [0,w,w,0], y .+ [0,0,h,h])
end

shapes = [rectangle(2,2,1,1), rectangle(2,2, 10,10)]
p = plot(xlim=(0,12), ylim=(0,12))
plot!(p, shapes; color=:orange, label="foo")

```

I should add that the rectangles are not all the same size, so I can’t just define a rectangular marker with `markershape` and do a scatter plot.

---

<div class="post-metadata">

**Author:** ![technocrat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/technocrat/32/220947_2.png) [@technocrat](https://discourse.julialang.org/u/technocrat)\
**Post date:** [October 4, 2025, 10:52pm UTC](https://discourse.julialang.org/t/plot-several-shapes-as-part-of-a-single-series-using-plots-jl/132878/2 "2025-10-04T22:52:20Z")

</div>

```julia-auto
using Plots

function rectangle(w, h, x, y; voffset=0)
    y -= 0.5*h
    if voffset != 0
        y += voffset*h
    end
    Shape(x .+ [0,w,w,0], y .+ [0,0,h,h])
end

shapes = [rectangle(2,2,1,1), rectangle(2,2, 10,10)]
p = plot(xlim=(0,12), ylim=(0,12))
plot!(p, shapes[1]; color=:orange, label="foo")
plot!(p, shapes[2]; color=:orange, label=false)

```

 ![CleanShot 2025-10-04 at 15.51.34@2x](https://global.discourse-cdn.com/julialang/original/3X/9/3/93daec03e6cda56412e2614e0c88a8a67016067c.png)

---

<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:** [October 5, 2025, 12:17pm UTC](https://discourse.julialang.org/t/plot-several-shapes-as-part-of-a-single-series-using-plots-jl/132878/3 "2025-10-05T12:17:15Z")

</div>

Please note that the OP’s code only required one slight edit of the keyword:

```julia
label=["" "foo"]

```

This approach can be generalised to N shapes as follows:

```julia
labels = fill("", 1, N)
labels[1] = "foo"

```

and then feed it to the plot as: label=labels
