# How to Automatically Generate Labels for \`ComposedFunction\`s in \`Plots.jl\`?

**URL:** https://discourse.julialang.org/t/how-to-automatically-generate-labels-for-composedfunction-s-in-plots-jl/122702
**Category:** General Usage
**Tags:** plotting, pretty-printing
**Created:** [November 16, 2024, 2:35am UTC](https://discourse.julialang.org/t/how-to-automatically-generate-labels-for-composedfunction-s-in-plots-jl/122702 "2024-11-16T02:35:08Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![singularitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/singularitti/32/17678_2.png) [@singularitti](https://discourse.julialang.org/u/singularitti)
#### Post date: [November 16, 2024, 2:35am UTC](https://discourse.julialang.org/t/how-to-automatically-generate-labels-for-composedfunction-s-in-plots-jl/122702/1 "2024-11-16T02:35:08Z")

</div>

I have the following code:

```julia
using Plots

f(x) = sin(x)
plot(1:10, f.(1:10); label="$f") # This works as expected; the label is "f".

g = f ∘ f
plot(1:10, g.(1:10); label="$g") # The label here is "Main.f ∘ Main.f", but I want it to be "f ∘ f".

```

The `Main` module prefix appears in the label when plotting composed functions. Is there a way to generate the correct label dynamically (e.g., “f ∘ f”) without manually specifying it? Ideally, I’d like this to work even if I compose functions multiple times (e.g., `f ∘ f ∘ f`).

How can I achieve this? Is there a general solution for automatically generating labels for such composed functions?

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/7/07c7a1f4e6822784cafb276470d5332e1f00f0f4.jpeg)

 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/5/85f38747ddeaf74dbec26fa038a415e68aea1412.jpeg)

---

<div class="post-metadata">

### Author: ![singularitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/singularitti/32/17678_2.png) [@singularitti](https://discourse.julialang.org/u/singularitti)
#### Post date: [November 18, 2024, 7:40am UTC](https://discourse.julialang.org/t/how-to-automatically-generate-labels-for-composedfunction-s-in-plots-jl/122702/2 "2024-11-18T07:40:54Z")

</div>

As [Julius Krumbiegel](https://github.com/jkrumbiegel) and Michael Abbott suggested on [Slack](https://julialang.slack.com/archives/C6E4SU1D3/p1731843364803399?thread_ts=1731724607.166019&cid=C6E4SU1D3), this is not a `Plots.jl` issue. I should use:

```julia
julia> g = f ∘ f
f ∘ f

julia> repr(g, context = :module => Main)
"f ∘ f"

julia> repr(g)
"Main.f ∘ Main.f"

```

Thanks to [Julius Krumbiegel](https://github.com/jkrumbiegel)!
