-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotly.jl
More file actions
153 lines (137 loc) · 3.14 KB
/
plotly.jl
File metadata and controls
153 lines (137 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using JavaScriptBridge
# Open browser/refresh http://localhost:8000/julia
JS.add("d3")
JS.add("plotly")
function add_div(id)
js"""
var div = document.getElementById("$(id)");
if (div === null) {
d3.select("body").append("div").attr("id","$(id)").attr("class","js-plotly-plot");
};
"""
end
n = 10
data = Dict[Dict("x"=>1:n,"y"=>rand(n))]
layout = Dict(
"title"=>"Create a new <div> and plot a single trace",
"width"=>600,
"height"=>300,
)
id = "Plot1"
add_div(id)
js"""
Plotly.newPlot("$(id)",$(data),$(layout));
"""
data = Dict[Dict("x"=>1:n,"y"=>rand(n)),Dict("x"=>1:n,"y"=>rand(n))]
layout = Dict(
"title"=>"Create a new <div> and plot an array of traces",
"width"=>600,
"height"=>300,
)
id = "Plot2"
add_div(id)
js"""
Plotly.newPlot("$(id)",$(data),$(layout))
"""
trace1 = Dict(
"x"=>[1, 2, 3, 4],
"y"=>[10, 15, 13, 17],
"mode"=>"markers")
trace2 = Dict(
"x"=>[2, 3, 4, 5],
"y"=>[16, 5, 11, 10],
"mode"=>"lines")
trace3 = Dict(
"x"=>[1, 2, 3, 4],
"y"=>[12, 9, 15, 12],
"mode"=>"lines+markers")
data = Dict[ trace1, trace2, trace3 ]
layout = Dict(
"title"=>"Line and Scatter Plot",
"height"=>400,
"width"=>480)
id = "Plot3"
add_div(id)
js"""
Plotly.newPlot("$(id)",$(data),$(layout))
"""
country = ["Switzerland (2011)", "Chile (2013)", "Japan (2014)", "United States (2012)", "Slovenia (2014)", "Canada (2011)", "Poland (2010)", "Estonia (2015)", "Luxembourg (2013)", "Portugal (2011)"];
votingPop = [40, 45.7, 52, 53.6, 54.1, 54.2, 54.5, 54.7, 55.1, 56.6];
regVoters = [49.1, 42, 52.7, 84.3, 51.7, 61.1, 55.3, 64.2, 91.1, 58.9];
trace1 = Dict(
"type"=>"scatter",
"x"=>votingPop,
"y"=>country,
"mode"=>"markers",
"name"=>"Percent of estimated voting age population",
"marker"=>Dict(
"color"=>"rgba(156, 165, 196, 0.95)",
"line"=>Dict(
"color"=>"rgba(156, 165, 196, 1.0)",
"width"=>1,
),
"symbol"=>"circle",
"size"=>16
)
)
trace2 = Dict(
"x"=>regVoters,
"y"=>country,
"mode"=>"markers",
"name"=>"Percent of estimated registered voters",
"marker"=>Dict(
"color"=>"rgba(204, 204, 204, 0.95)",
"line"=>Dict(
"color"=>"rgba(217, 217, 217, 1.0)",
"width"=>1,
),
"symbol"=>"circle",
"size"=>16
)
)
data = Dict[trace1, trace2]
layout = Dict(
"title"=>"Votes cast for ten lowest voting age population in OECD countries",
"xaxis"=>Dict(
"showgrid"=>false,
"showline"=>true,
"linecolor"=>"rgb(102, 102, 102)",
"titlefont"=>Dict(
"font"=>Dict(
"color"=>"rgb(204, 204, 204)"
)
),
"tickfont"=>Dict(
"font"=>Dict(
"color"=>"rgb(102, 102, 102)"
)
),
"autotick"=>false,
"dtick"=>10,
"ticks"=>"outside",
"tickcolor"=>"rgb(102, 102, 102)"
),
"margin"=>Dict(
"l"=>140,
"r"=>40,
"b"=>50,
"t"=>80
),
"legend"=>Dict(
"font"=>Dict(
"size"=>10,
),
"yanchor"=>"middle",
"xanchor"=>"right"
),
"width"=>600,
"height"=>600,
"paper_bgcolor"=>"rgb(254, 247, 234)",
"plot_bgcolor"=>"rgb(254, 247, 234)",
"hovermode"=>"closest"
)
id = "Plot4"
add_div(id)
js"""
Plotly.newPlot("$(id)",$(data),$(layout));
"""