Plotly is free for unlimited public use. Sign up for free!

Sensitive data? Upgrade to a paid plan

Show Sidebar Hide Sidebar

Legends in Julia

How to modify the legend in julia graphs. Seven examples of how to move, color, and hide the legend.

# Learn about API authentication here: https://plot.ly/julia/getting-started
# Find your api_key here: https://plot.ly/settings/api

using Plotly


trace1 = [
  "x" => [0, 1, 2, 3, 4, 5, 6, 7, 8],
  "y" => [0, 3, 6, 4, 5, 2, 3, 5, 4],
  "type" => "scatter"
]
trace2 = [
  "x" => [0, 1, 2, 3, 4, 5, 6, 7, 8],
  "y" => [0, 4, 7, 8, 3, 6, 3, 3, 4],
  "type" => "scatter"
]
data = [trace1, trace2]
layout = ["showlegend" => false]
response = Plotly.plot(data, ["layout" => layout, "filename" => "legend-visibility", "fileopt" => "overwrite"])
plot_url = response["url"]
# Learn about API authentication here: https://plot.ly/julia/getting-started
# Find your api_key here: https://plot.ly/settings/api

using Plotly


trace1 = [
  "x" => [0, 1, 2, 3, 4, 5, 6, 7, 8],
  "y" => [0, 3, 6, 4, 5, 2, 3, 5, 4],
  "name" => "Blue Trace",
  "type" => "scatter"
]
trace2 = [
  "x" => [0, 1, 2, 3, 4, 5, 6, 7, 8],
  "y" => [0, 4, 7, 8, 3, 6, 3, 3, 4],
  "name" => "Orange Trace",
  "type" => "scatter"
]
data = [trace1, trace2]
response = Plotly.plot(data, ["filename" => "legend-labels", "fileopt" => "overwrite"])
plot_url = response["url"]
# Learn about API authentication here: https://plot.ly/julia/getting-started
# Find your api_key here: https://plot.ly/settings/api

using Plotly


trace1 = [
  "x" => [0, 1, 2, 3, 4, 5, 6, 7, 8],
  "y" => [0, 3, 6, 4, 5, 2, 3, 5, 4],
  "type" => "scatter"
]
trace2 = [
  "x" => [0, 1, 2, 3, 4, 5, 6, 7, 8],
  "y" => [0, 4, 7, 8, 3, 6, 3, 3, 4],
  "type" => "scatter"
]
data = [trace1, trace2]
layout = [
  "showlegend" => true,
  "legend" => [
    "x" => 1,
    "y" => 1
  ]
]
response = Plotly.plot(data, ["layout" => layout, "filename" => "legend-inside", "fileopt" => "overwrite"])
plot_url = response["url"]
# Learn about API authentication here: https://plot.ly/julia/getting-started
# Find your api_key here: https://plot.ly/settings/api

using Plotly


trace1 = [
  "x" => [0, 1, 2, 3, 4, 5, 6, 7, 8],
  "y" => [0, 3, 6, 4, 5, 2, 3, 5, 4],
  "type" => "scatter"
]
trace2 = [
  "x" => [0, 1, 2, 3, 4, 5, 6, 7, 8],
  "y" => [0, 4, 7, 8, 3, 6, 3, 3, 4],
  "type" => "scatter"
]
data = [trace1, trace2]
layout = [
  "showlegend" => true,
  "legend" => [
    "x" => 100,
    "y" => 1
  ]
]
response = Plotly.plot(data, ["layout" => layout, "filename" => "legend-outside", "fileopt" => "overwrite"])
plot_url = response["url"]
# Learn about API authentication here: https://plot.ly/julia/getting-started
# Find your api_key here: https://plot.ly/settings/api

using Plotly


trace1 = [
  "x" => [0, 1, 2, 3, 4, 5, 6, 7, 8],
  "y" => [0, 3, 6, 4, 5, 2, 3, 5, 4],
  "type" => "scatter"
]
trace2 = [
  "x" => [0, 1, 2, 3, 4, 5, 6, 7, 8],
  "y" => [0, 4, 7, 8, 3, 6, 3, 3, 4],
  "type" => "scatter"
]
data = [trace1, trace2]
layout = ["legend" => [
    "x" => 0,
    "y" => 1,
    "traceorder" => "normal",
    "font" => [
      "family" => "sans-serif",
      "size" => 12,
      "color" => "#000"
    ],
    "bgcolor" => "#E2E2E2",
    "bordercolor" => "#FFFFFF",
    "borderwidth" => 2
  ]]
response = Plotly.plot(data, ["layout" => layout, "filename" => "legend-style", "fileopt" => "overwrite"])
plot_url = response["url"]
# Learn about API authentication here: https://plot.ly/julia/getting-started
# Find your api_key here: https://plot.ly/settings/api

using Plotly


trace1 = [
  "x" => [0, 1, 2],
  "y" => [1, 2, 3],
  "name" => "First Trace",
  "showlegend" => false,
  "type" => "scatter"
]
trace2 = [
  "x" => [0, 1, 2, 3],
  "y" => [8, 4, 2, 0],
  "name" => "Second Trace",
  "showlegend" => true,
  "type" => "scatter"
]
data = [trace1, trace2]
response = Plotly.plot(data, ["filename" => "show-legend", "fileopt" => "overwrite"])
plot_url = response["url"]
Still need help?
Contact Us

For guaranteed 24 hour response turnarounds, upgrade to a Developer Support Plan.