API for coders REST API
Julia
How to use PlotAPI with Julia.
In this demonstration, we'll use some sample data to create an interactive PlotAPI Chord diagram with Julia.
using HTTP
using JSON
using Base64
matrix = [
[0, 5, 6, 4, 7, 4],
[5, 0, 5, 4, 6, 5],
[6, 5, 0, 4, 5, 5],
[4, 4, 4, 0, 5, 5],
[7, 6, 5, 5, 0, 4],
[4, 5, 5, 5, 4, 0],
]
names = ["Action", "Adventure", "Comedy", "Drama", "Fantasy", "Thriller"]
params = Dict("matrix" => matrix, "names" => names)
auth = "Basic " * Base64.base64encode("api_key" * ":" * your_api_key)
r = HTTP.request("POST", "https://plotapi.com/chord",
["Content-Type" => "application/json", "Authorization" => auth],
JSON.json(params))
html_content = String(r.body)
Saving locally
We can save the to a HTML file.
open("plot.html", "w") do io
write(io, html_content)
end;
Displaying in notebook
When working from a Jupyter Notebook, you can also make use of display()
and HTML()
to display the visualization inline.
display(HTML(html_content))
Another example
Let's use Julia to create a PlotAPI Sankey diagram.
using HTTP
using JSON
using Base64
links = [
Dict("source" => "Group A", "target" => "Rank 1", "value" => 1000),
Dict("source" => "Group B", "target" => "Rank 1", "value" => 300),
Dict("source" => "Group B", "target" => "Rank 2", "value" => 600),
Dict("source" => "Group B", "target" => "Rank 3", "value" => 400),
Dict("source" => "Rank 1", "target" => "Club A", "value" => 700),
Dict("source" => "Rank 1", "target" => "Club B", "value" => 400),
Dict("source" => "Rank 1", "target" => "Club C", "value" => 200),
Dict("source" => "Rank 2", "target" => "Club B", "value" => 200),
Dict("source" => "Rank 2", "target" => "Club C", "value" => 400),
Dict("source" => "Rank 3", "target" => "Withdrawn", "value" => 400),
Dict("source" => "Club A", "target" => "The Most Amazing Prize", "value" => 500),
]
params = Dict("links" => links)
auth = "Basic " * Base64.base64encode("api_key" * ":" * your_api_key)
r = HTTP.request("POST", "https://plotapi.com/sankey",
["Content-Type" => "application/json", "Authorization" => auth],
JSON.json(params))
html_content = String(r.body)
open("output.html", "w") do f
write(f, html_content)
end