logo

Hiding Specific Data Labels in Julia Plots 📂Julia

Hiding Specific Data Labels in Julia Plots

Code 1

using Plots

x = rand(30)
y = rand(30)
z = rand(30)

plot(x)
plot!(y)
plot!(z)
png("result1")

result1

In some cases, you might want to make only certain data labels appear in the legend, as shown above.

label = ""

plot(x, label = "")
plot!(y)
png("result2")

result2

In such cases, you can set the option label = "". As you can see, the first data is displayed in the figure, but it does not appear in the legend.

primary = false

plot!(z, primary = false)
png("result3")

result3

Another way is to set the primary = false option, as shown. The last data is plotted in orange and hidden in the legend. Since this is a side effect of turning off primary, it’s better to only tweak the label option if possible.

Environment

  • OS: Windows
  • julia: v1.6.2