Skip to content

Commit 14f12f0

Browse files
Merge branch 'master' of https://github.com/plotly/Plotly.jl
Conflicts: .travis.yml
2 parents b80624b + ccb5679 commit 14f12f0

File tree

5 files changed

+284
-87
lines changed

5 files changed

+284
-87
lines changed

README.md

Lines changed: 132 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#A Julia interface to the plot.ly API
1+
# A Julia interface to the plot.ly API
2+
3+
[![Build Status](https://travis-ci.org/snotskie/Plotly.jl.png)](https://travis-ci.org/snotskie/Plotly.jl)
24

35
Forked from [astrieanna/Plotly.jl](https://github.com/astrieanna/Plotly.jl)
46

@@ -8,62 +10,152 @@ README quickly to get started. Alternately, checkout out the pretty Julia docs a
810

911
Given that you have Julia v0.2.1,
1012

11-
Pkg.clone("https://github.com/plotly/Plotly.jl")
13+
```julia
14+
Pkg.clone("https://github.com/plotly/Plotly.jl")
15+
```
1216

1317
## Usage
14-
15-
julia> using Plotly
16-
INFO: Cloning Plotly from https://github.com/plotly/Plotly.jl
17-
INFO: Computing changes...
18-
INFO: No packages to install, update or remove.
19-
18+
```julia
19+
julia> using Plotly
20+
INFO: Cloning Plotly from https://github.com/plotly/Plotly.jl
21+
INFO: Computing changes...
22+
INFO: No packages to install, update or remove.
23+
```
2024

2125
You'll need to create a plot.ly account and find out your API key before you'll be able to use this package.
26+
2227
## New user signup
23-
julia> Plotly.signup("username","email")
24-
Success! Check your email to activate account.
25-
28+
```julia
29+
julia> Plotly.signup("username","email")
30+
Success! Check your email to activate account.
31+
```
32+
2633
## Signin
27-
julia> Plotly.signin("username","your api key")
28-
PlotlyAccount("username","your api key")
34+
```julia
35+
julia> Plotly.signin("username","your api key")
36+
PlotlyAccount("username","your api key")
37+
```
2938

3039
## Plot && Open in browser
31-
julia> Plotly.openurl(Plotly.plot(["z"=>rand(6,6)],["style"=>["type"=>"heatmap"]]))
32-
START /bin/firefox "https://plot.ly/~astrieanna/0"
33-
40+
```julia
41+
julia> Plotly.openurl(Plotly.plot(["z"=>rand(6,6)],["style"=>["type"=>"heatmap"]]))
42+
START /bin/firefox "https://plot.ly/~astrieanna/0"
43+
```
44+
3445
That last line is what the REPL prints out,
3546
as a Firefox tab opens with the plot.
3647
You can also just call `plot` by itself, and you'll get a String that's the url of your chart.
3748

3849
## Style and Layout
39-
julia> Plotly.style(["line"=>["color"=>"rgb(255,0,0)","width"=>10]])
40-
41-
julia> Plotly.layout(["layout"=>["title"=>"Time Wasted"]])
42-
43-
## Plot Functions and Polynomials
44-
julia> Plotly.plot(abs)
45-
julia> Plotly.plot([sqrt, log], ["left"=>10, "right"=>20, "step"=>0.1])
50+
```julia
51+
julia> Plotly.style(["line"=>["color"=>"rgb(255,0,0)","width"=>10]])
52+
julia> Plotly.layout(["layout"=>["title"=>"Time Wasted"]])
53+
```
54+
55+
# Quick Plotting
56+
## Functions and Polynomials
57+
```julia
58+
julia> Plotly.plot(abs)
59+
julia> Plotly.plot([sqrt, log], ["left"=>10, "right"=>20, "step"=>0.1])
60+
julia> Plotly.plot() do x
61+
savings = 3000
62+
income = x*1000
63+
expenses = x*800
64+
return savings+income-expenses
65+
end
66+
```
4667

4768
You can now plot functions directly.
4869
The first line shows how to plot the absolute value function, and the second line plots
4970
the square root and logarithm functions, both from 10 to 20 at increments of 0.1.
71+
The last line shows how to use Julia's `do` syntax to plot complicated anonymous functions.
5072

51-
julia> using Polynomial
52-
julia> x = Poly([1,0])
53-
julia> Plotly.plot(3x^3 + 2x^2 - x + 1)
73+
```julia
74+
julia> using Polynomial
75+
julia> x = Poly([1,0])
76+
julia> Plotly.plot(3x^3 + 2x^2 - x + 1)
77+
julia> Plotly.plot([x, 2x, 3x^2-x])
78+
```
5479

55-
If you have the Polynomial package installed, you can plot them directly the same way as math functions.
80+
Using the Polynomial package, you can plot polynomials directly the same way as math functions.
5681

57-
## Plot TimeSeries
58-
julia> using TimeSeries
59-
julia> d = [date(2012,5,29):date(2013,5,29)]
60-
julia> t = TimeArray(d, rand(length(d),2), ["foo","bar"])
61-
julia> Plotly.plot(t)
62-
63-
If you have the TimeSeries package installed, you can plot them directly by passing a TimeArray argument.
64-
65-
## Plot WAV Files
66-
julia> using WAV
67-
julia> Plotly.plot(wavread("filename.wav"))
68-
69-
If you have the WAV package installed, you can plot WAV files by passing a call to the wavread function.
82+
## DataFrames and TimeSeries
83+
```julia
84+
julia> using DataFrames
85+
julia> df = readtable("height_vs_weight.csv")
86+
julia> Plotly.plot(df, ["xs"=>:height, "ys"=>:weight])
87+
```
88+
89+
Using the DataFrames package, you can read CSV data and plot it directly by passing the data frame and setting the xs and/or ys options. These are symbols or arrays of symbols refering to columns names in the CSV file.
90+
91+
```julia
92+
julia> using TimeSeries
93+
julia> d = [date(2012,5,29):date(2013,5,29)]
94+
julia> t = TimeArray(d, rand(length(d),2), ["foo","bar"])
95+
julia> Plotly.plot(t)
96+
```
97+
98+
Using the TimeSeries package, you can plot them directly by passing a TimeArray argument.
99+
100+
## WAV Files
101+
```julia
102+
julia> using WAV
103+
julia> Plotly.plot(wavread("filename.wav"))
104+
```
105+
106+
Using the WAV package, you can plot WAV files by passing a call to the `wavread` function.
107+
108+
# Detailed Plotting
109+
## Arrays and Dicts
110+
```julia
111+
julia> trace1 = Plotly.line([3x for x in 1:1000])
112+
julia> trace2 = Plotly.histogram([3x for x in 1:1000])
113+
julia> trace3 = Plotly.scatter([2x => 3x for x in 1:1000])
114+
julia> trace4 = Plotly.box([2x => 3x for x in 1:1000])
115+
julia
116+
```
117+
118+
## Functions and Polynomials
119+
```julia
120+
julia> trace1 = Plotly.line(abs, ["left"=>10, "right"=>20, "step"=>0.1])
121+
julia> trace2 = Plotly.box(sin, ["left"=>10, "right"=>20, "step"=>0.1])
122+
julia> trace3 = Plotly.scatter(cos, ["left"=>10, "right"=>20, "step"=>0.1])
123+
julia> trace4 = Plotly.histogram(cos, ["left"=>10, "right"=>20, "step"=>0.1])
124+
julia> Plotly.plot([trace1, trace2, trace3, trace4])
125+
126+
julia> using Polynomial
127+
julia> x = Poly([1,0])
128+
julia> trace1 = Plotly.line(3x^3 + 2x^2 - x + 1)
129+
julia> trace2 = Plotly.histogram(3x^3 + 2x^2 - x + 1)
130+
julia> Plotly.plot([trace1, trace2])
131+
```
132+
133+
## DataFrames and TimeSeries
134+
```julia
135+
julia> using DataFrames
136+
julia> df = readtable("height_vs_weight.csv")
137+
julia> trace1 = Plotly.line(df, ["xs"=>:height, "ys"=>:weight])
138+
julia> trace2 = Plotly.scatter(df, ["xs"=>:height, "ys"=>:weight])
139+
julia> trace3 = Plotly.histogram(df, ["xs"=>:height])
140+
julia> trace4 = Plotly.box(df, ["ys"=>:weight])
141+
julia> Plotly.plot([trace1, trace2, trace3, trace4])
142+
143+
julia> using TimeSeries
144+
julia> d = [date(2012,5,29):date(2013,5,29)]
145+
julia> t = TimeArray(d, rand(length(d),2), ["foo","bar"])
146+
julia> trace1 = Plotly.line(t)
147+
julia> trace2 = Plotly.scatter(t)
148+
julia> trace3 = Plotly.box(t)
149+
julia> trace4 = Plotly.histogram(t)
150+
julia> Plotly.plot([trace1, trace2, trace3, trace4])
151+
```
152+
153+
## WAV Files
154+
```julia
155+
julia> using WAV
156+
julia> trace1 = Plotly.line(wavread("filename.wav"))
157+
julia> trace2 = Plotly.histogram(wavread("filename.wav"))
158+
julia> trace3 = Plotly.box(wavread("filename.wav"))
159+
julia> trace4 = Plotly.scatter(wavread("filename.wav"))
160+
julia> Plotly.plot([trace1, trace2, trace3, trace4])
161+
```

src/Plotly.jl

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ type CurrentPlot
1313
url::String
1414
end
1515

16-
default_options = ["filename"=>"Plot from Julia API",
16+
default_options = {"filename"=>"Plot from Julia API",
1717
"world_readable"=> true,
18-
"layout"=>[""=>""]]
18+
"layout"=>{""=>""}}
1919

2020
## Taken from https://github.com/johnmyleswhite/Vega.jl/blob/master/src/Vega.jl#L51
2121
# Open a URL in a browser
@@ -25,16 +25,16 @@ function openurl(url::String)
2525
@linux_only run(`xdg-open $url`)
2626
end
2727

28-
default_opts = [
28+
default_opts = {
2929
"origin" => "plot",
3030
"platform" => "Julia",
31-
"version" => "0.2"]
31+
"version" => "0.2"}
3232

3333
function signup(username::String, email::String)
3434
r = HTTPClient.HTTPC.post("http://plot.ly/apimkacct",
3535
merge(default_opts,
36-
["un" => username,
37-
"email" => email]))
36+
{"un" => username,
37+
"email" => email}))
3838
if r.http_code == 200
3939
results = JSON.parse(bytestring(r.body))
4040
for flag in ["error","warning","message"]
@@ -63,10 +63,10 @@ function plot(data::Array,options=Dict())
6363
opt = merge(default_options,options)
6464
r = HTTPClient.HTTPC.post("http://plot.ly/clientresp",
6565
merge(default_opts,
66-
["un" => plotlyaccount.username,
66+
{"un" => plotlyaccount.username,
6767
"key" => plotlyaccount.api_key,
6868
"args" => json(data),
69-
"kwargs" => json(opt)]))
69+
"kwargs" => json(opt)}))
7070
body=JSON.parse(bytestring(r.body))
7171
if r.http_code != 200
7272
error(["r.http_code"])
@@ -92,11 +92,11 @@ function layout(layout_opts::Dict,meta_opts=Dict())
9292

9393
r = HTTPClient.HTTPC.post("http://plot.ly/clientresp",
9494
merge(default_opts,
95-
["un" => plotlyaccount.username,
95+
{"un" => plotlyaccount.username,
9696
"key" => plotlyaccount.api_key,
9797
"args" => json(layout_opts),
9898
"origin" => "layout",
99-
"kwargs" => json(meta_opts)]))
99+
"kwargs" => json(meta_opts)}))
100100
__parseresponse(r)
101101
end
102102

@@ -111,11 +111,11 @@ function style(style_opts,meta_opts=Dict())
111111

112112
r = HTTPClient.HTTPC.post("http://plot.ly/clientresp",
113113
merge(default_opts,
114-
["un" => plotlyaccount.username,
114+
{"un" => plotlyaccount.username,
115115
"key" => plotlyaccount.api_key,
116116
"args" => json([style_opts]),
117117
"origin" => "style",
118-
"kwargs" => json(meta_opts)]))
118+
"kwargs" => json(meta_opts)}))
119119
__parseresponse(r)
120120
end
121121

@@ -148,9 +148,9 @@ end
148148

149149
function get_template(format_type::String)
150150
if format_type == "layout"
151-
return [
151+
return {
152152
"title"=>"Click to enter Plot title",
153-
"xaxis"=>[
153+
"xaxis"=>{
154154
"range"=>[-1,6],
155155
"type"=>"-",
156156
"mirror"=>true,
@@ -177,9 +177,9 @@ function get_template(format_type::String)
177177
"zerolinewidth"=>1,
178178
"title"=>"Click to enter X axis title",
179179
"unit"=>"",
180-
"titlefont"=>["family"=>"","size"=>0,"color"=>""],
181-
"tickfont"=>["family"=>"","size"=>0,"color"=>""]],
182-
"yaxis"=>[
180+
"titlefont"=>{"family"=>"","size"=>0,"color"=>""},
181+
"tickfont"=>{"family"=>"","size"=>0,"color"=>""}},
182+
"yaxis"=>{
183183
"range"=>[-1,4],
184184
"type"=>"-",
185185
"mirror"=>true,
@@ -206,18 +206,18 @@ function get_template(format_type::String)
206206
"zerolinewidth"=>1,
207207
"title"=>"Click to enter Y axis title",
208208
"unit"=>"",
209-
"titlefont"=>["family"=>"","size"=>0,"color"=>""],
210-
"tickfont"=>["family"=>"","size"=>0,"color"=>""]],
211-
"legend"=>[
209+
"titlefont"=>{"family"=>"","size"=>0,"color"=>""},
210+
"tickfont"=>{"family"=>"","size"=>0,"color"=>""}},
211+
"legend"=>{
212212
"bgcolor"=>"#fff",
213213
"bordercolor"=>"#000",
214214
"borderwidth"=>1,
215-
"font"=>["family"=>"","size"=>0,"color"=>""],
216-
"traceorder"=>"normal"],
215+
"font"=>{"family"=>"","size"=>0,"color"=>""},
216+
"traceorder"=>"normal"},
217217
"width"=>700,
218218
"height"=>450,
219219
"autosize"=>"initial",
220-
"margin"=>["l"=>80,"r"=>80,"t"=>80,"b"=>80,"pad"=>2],
220+
"margin"=>{"l"=>80,"r"=>80,"t"=>80,"b"=>80,"pad"=>2},
221221
"paper_bgcolor"=>"#fff",
222222
"plot_bgcolor"=>"#fff",
223223
"barmode"=>"stack",
@@ -226,10 +226,10 @@ function get_template(format_type::String)
226226
"boxmode"=>"overlay",
227227
"boxgap"=>0.3,
228228
"boxgroupgap"=>0.3,
229-
"font"=>["family"=>"Arial, sans-serif;","size"=>12,"color"=>"#000"],
230-
"titlefont"=>["family"=>"","size"=>0,"color"=>""],
229+
"font"=>{"family"=>"Arial, sans-serif;","size"=>12,"color"=>"#000"},
230+
"titlefont"=>{"family"=>"","size"=>0,"color"=>""},
231231
"dragmode"=>"zoom",
232-
"hovermode"=>"x"]
232+
"hovermode"=>"x"}
233233
end
234234
end
235235

0 commit comments

Comments
 (0)