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

Sensitive data? Upgrade to a paid plan

Show Sidebar Hide Sidebar

Text and Annotations in Julia

How to add text labels and annotations to plots in julia.

# 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, 1, 1],
  "mode" => "lines+markers+text",
  "name" => "Lines, Markers and Text",
  "text" => ["Text A", "Text B", "Text C"],
  "textposition" => "top",
  "type" => "scatter"
]
trace2 = [
  "x" => [0, 1, 2],
  "y" => [2, 2, 2],
  "mode" => "markers+text",
  "name" => "Markers and Text",
  "text" => ["Text D", "Text E", "Text F"],
  "textposition" => "bottom",
  "type" => "scatter"
]
trace3 = [
  "x" => [0, 1, 2],
  "y" => [3, 3, 3],
  "mode" => "lines+text",
  "name" => "Lines and Text",
  "text" => ["Text G", "Text H", "Text I"],
  "textposition" => "bottom",
  "type" => "scatter"
]
data = [trace1, trace2, trace3]
layout = ["showlegend" => false]
response = Plotly.plot(data, ["layout" => layout, "filename" => "text-chart-basic", "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


data = [
  [
    "x" => [0, 1, 2],
    "y" => [1, 3, 2],
    "mode" => "markers",
    "text" => ["Text A", "Text B", "Text C"],
    "type" => "scatter"
  ]
]
layout = ["title" => "Hover over the points to see the text"]
response = Plotly.plot(data, ["layout" => layout, "filename" => "hover-chart-basic", "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, 1, 3, 2, 4, 3, 4, 6, 5],
  "type" => "scatter"
]
trace2 = [
  "x" => [0, 1, 2, 3, 4, 5, 6, 7, 8],
  "y" => [0, 4, 5, 1, 2, 2, 3, 4, 2],
  "type" => "scatter"
]
data = [trace1, trace2]
layout = [
  "showlegend" => false,
  "annotations" => [
    [
      "x" => 2,
      "y" => 5,
      "xref" => "x",
      "yref" => "y",
      "text" => "Annotation Text",
      "showarrow" => true,
      "arrowhead" => 7,
      "ax" => 0,
      "ay" => -40
    ]
  ]
]
response = Plotly.plot(data, ["layout" => layout, "filename" => "simple-annotation", "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, 1, 3, 2, 4, 3, 4, 6, 5],
  "type" => "scatter"
]
trace2 = [
  "x" => [0, 1, 2, 3, 4, 5, 6, 7, 8],
  "y" => [0, 4, 5, 1, 2, 2, 3, 4, 2],
  "type" => "scatter"
]
data = [trace1, trace2]
layout = [
  "showlegend" => false,
  "annotations" => [
    [
      "x" => 2,
      "y" => 5,
      "xref" => "x",
      "yref" => "y",
      "text" => "Annotation Text",
      "showarrow" => true,
      "arrowhead" => 7,
      "ax" => 0,
      "ay" => -40
    ],
    [
      "x" => 4,
      "y" => 4,
      "xref" => "x",
      "yref" => "y",
      "text" => "Annotation Text 2",
      "showarrow" => true,
      "arrowhead" => 7,
      "ax" => 0,
      "ay" => -40
    ]
  ]
]
response = Plotly.plot(data, ["layout" => layout, "filename" => "multiple-annotation", "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, 1, 1],
  "mode" => "lines+markers+text",
  "name" => "Lines, Markers and Text",
  "text" => ["Text A", "Text B", "Text C"],
  "textposition" => "top right",
  "textfont" => [
    "family" => "sans serif",
    "size" => 18,
    "color" => "#1f77b4"
  ],
  "type" => "scatter"
]
trace2 = [
  "x" => [0, 1, 2],
  "y" => [2, 2, 2],
  "mode" => "lines+markers+text",
  "name" => "Lines and Text",
  "text" => ["Text G", "Text H", "Text I"],
  "textposition" => "bottom",
  "textfont" => [
    "family" => "sans serif",
    "size" => 18,
    "color" => "#ff7f0e"
  ],
  "type" => "scatter"
]
data = [trace1, trace2]
layout = ["showlegend" => false]
response = Plotly.plot(data, ["layout" => layout, "filename" => "text-chart-styling", "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, 1, 3, 2, 4, 3, 4, 6, 5],
  "type" => "scatter"
]
trace2 = [
  "x" => [0, 1, 2, 3, 4, 5, 6, 7, 8],
  "y" => [0, 4, 5, 1, 2, 2, 3, 4, 2],
  "type" => "scatter"
]
data = [trace1, trace2]
layout = [
  "showlegend" => false,
  "annotations" => [
    [
      "x" => 2,
      "y" => 5,
      "xref" => "x",
      "yref" => "y",
      "text" => "max=5",
      "showarrow" => true,
      "font" => [
        "family" => "Courier New, monospace",
        "size" => 16,
        "color" => "#ffffff"
      ],
      "align" => "center",
      "arrowhead" => 2,
      "arrowsize" => 1,
      "arrowwidth" => 2,
      "arrowcolor" => "#636363",
      "ax" => 20,
      "ay" => -30,
      "bordercolor" => "#c7c7c7",
      "borderwidth" => 2,
      "borderpad" => 4,
      "bgcolor" => "#ff7f0e",
      "opacity" => 0.8
    ]
  ]
]
response = Plotly.plot(data, ["layout" => layout, "filename" => "style-annotation", "fileopt" => "overwrite"])
plot_url = response["url"]
Still need help?
Contact Us

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