Debian Codegraph @

tests/data/notebooks/outputs/ipynb_to_myst/julia_benchmark_plotly_barchart.md

raw
1 ---
2 kernelspec:
3 display_name: Julia 1.1.1
4 language: julia
5 name: julia-1.1
6 ---
7
8 ```{code-cell}
9 # IJulia rocks! So does Plotly. Check it out
10
11 using Plotly
12 api_key = "" # visit https://plot.ly/api to generate an API username and password
13 username = ""
14
15 Plotly.signin(username, api_key)
16 ```
17
18 ```{code-cell}
19 # Following data taken from http://julialang.org/ frontpage
20 benchmarks = ["fib", "parse_int", "quicksort3", "mandel", "pi_sum", "rand_mat_stat", "rand_mat_mul"]
21 platforms = ["Fortran", "Julia", "Python", "R", "Matlab", "Mathematica", "Javascript", "Go"]
22
23 data = {
24 platforms[1] => [0.26, 5.03, 1.11, 0.86, 0.80, 0.64, 0.96],
25 platforms[2] => [0.91, 1.60, 1.14, 0.85, 1.00, 1.66, 1.01],
26 platforms[3] => [30.37, 13.95, 31.98, 14.19, 16.33, 13.52, 3.41 ],
27 platforms[4] => [411.36, 59.40, 524.29, 106.97, 15.42, 10.84, 3.98 ],
28 platforms[5] => [1992.00, 1463.16, 101.84, 64.58, 1.29, 6.61, 1.10 ],
29 platforms[6] => [64.46, 29.54, 35.74, 6.07, 1.32, 4.52, 1.16 ],
30 platforms[7] => [2.18, 2.43, 3.51, 3.49, 0.84, 3.28, 14.60],
31 platforms[8] => [1.03, 4.79, 1.25, 2.36, 1.41, 8.12, 8.51]
32 }
33
34 pdata = [ {"x"=>benchmarks,"y"=>data[k],"bardir"=>"h","type"=>"bar","name"=>k} for k = platforms ]
35
36 layout = {
37 "title"=> "Julia benchmark comparison (smaller is better, C performance = 1.0)",
38 "barmode"=> "group",
39 "autosize"=> false,
40 "width"=> 900,
41 "height"=> 900,
42 "titlefont"=>
43 {
44 "family"=> "Open Sans",
45 "size"=> 18,
46 "color"=> "rgb(84, 39, 143)"
47 },
48 "margin"=> {"l"=>160, "pad"=>0},
49 "xaxis"=> {
50 "title"=> "Benchmark log-time",
51 "type"=> "log"
52 },
53 "yaxis"=> {"title"=> "Benchmark Name"}
54 }
55
56 response = Plotly.plot(pdata,["layout"=>layout])
57
58 # Embed in an iframe within IJulia
59 s = string("<iframe height='750' id='igraph' scrolling='no' seamless='seamless' src='",
60 response["url"],
61 "/700/700' width='750'></iframe>")
62 display("text/html", s)
63 ```
64
65 ```{code-cell}
66 # checkout https://plot.ly/api/ for more Julia examples!
67 # But to show off some other Plotly features:
68 x = 1:1500
69 y1 = sin(2*pi*x/1500.) + rand(1500)-0.5
70 y2 = sin(2*pi*x/1500.)
71
72 fish = {"x"=>x,"y"=> y1,
73 "type"=>"scatter","mode"=>"markers",
74 "marker"=>{"color"=>"rgb(0, 0, 255)","opacity"=>0.5 } }
75
76 fit = {"x"=> x,"y"=> y2,
77 "type"=>"scatter", "mode"=>"markers", "opacity"=>0.8,
78 "marker"=>{"color"=>"rgb(255, 0, 0)"} }
79
80 layout = {"autosize"=> false,
81 "width"=> 650, "height"=> 550,
82 "title"=>"Fish School",
83 "xaxis"=>{ "ticks"=> "",
84 "gridcolor"=> "white",
85 "zerolinecolor"=> "white",
86 "linecolor"=> "white",
87 "autorange"=> false,
88 "range"=>[0,1500] },
89 "yaxis"=>{ "ticks"=> "",
90 "gridcolor"=> "white",
91 "zerolinecolor"=> "white",
92 "linecolor"=> "white",
93 "autorange"=> false,
94 "range"=>[-2.2,2.2] },
95 "plot_bgcolor"=> "rgb(245,245,247)",
96 "showlegend"=> false,
97 "hovermode"=> "closest"}
98
99 response = Plotly.plot([fish, fit],["layout"=>layout])
100 s = string("<iframe height='750' id='igraph' scrolling='no' seamless='seamless' src='",
101 response["url"],
102 "/700/700' width='750'></iframe>")
103 display("text/html", s)
104 ```