|
1 | | -# A Julia interface to the plot.ly API |
| 1 | +# A Julia interface to the plot.ly plotting library and cloud services |
2 | 2 |
|
3 | 3 | [](https://travis-ci.org/plotly/Plotly.jl) |
4 | 4 |
|
5 | | -README quickly to get started. Alternately, checkout out the pretty Julia docs at https://plot.ly/julia/ |
6 | | - |
7 | 5 | ## Installation |
8 | 6 |
|
9 | | -Given that you have Julia v0.2.1, |
| 7 | +Simply run `Pkg.add("Plotly")`. |
10 | 8 |
|
11 | | -```julia |
12 | | -Pkg.clone("https://github.com/plotly/Plotly.jl") |
13 | | -``` |
| 9 | +## Plotting |
| 10 | + |
| 11 | +Plotting functions provided by this package are identical to [PlotlyJS](https://github.com/spencerlyon2/PlotlyJS.jl). Please consult its [documentation](http://spencerlyon.com/PlotlyJS.jl/). |
| 12 | + |
| 13 | +For example, this will display a basic scatter plot: |
14 | 14 |
|
15 | | -## Usage |
16 | | -```julia |
17 | | -julia> using Plotly |
18 | | -INFO: Cloning Plotly from https://github.com/plotly/Plotly.jl |
19 | | -INFO: Computing changes... |
20 | | -INFO: No packages to install, update or remove. |
| 15 | +``` |
| 16 | +my_plot = plot([scatter(x=[1,2], y=[3,4])], Layout(title="My plot")) |
21 | 17 | ``` |
22 | 18 |
|
23 | | -You'll need to create a plot.ly account and find out your API key before you'll be able to use this package. |
| 19 | +## Using the Plotly cloud |
24 | 20 |
|
25 | | -## New user signup |
| 21 | +### New user signup |
26 | 22 | Find your username and API key in the [Plotly settings](https://plot.ly/settings). |
27 | 23 |
|
28 | | -## Signin |
| 24 | +### Signin |
29 | 25 | ```julia |
30 | 26 | julia> Plotly.signin("username","your api key") |
31 | 27 | PlotlyAccount("username","your api key") |
32 | 28 | ``` |
33 | 29 |
|
34 | | -Note: you may also specify your session endpoints using signin as follows: |
| 30 | +Note: you may also specify your session endpoints using signin as follows: |
35 | 31 |
|
36 | 32 | ```julia |
37 | 33 | julia> Plotly.signin("username","your api key",Dict("plotly_domain"=> "your_plotly_base_endpoint", "plotly_api_domain"=> "your_plotly_api_endpoint")) |
38 | 34 | ``` |
39 | 35 |
|
40 | | -## Saving your credentials |
| 36 | +### Saving your credentials |
41 | 37 | ```julia |
42 | 38 | julia> Plotly.set_credentials_file(Dict("username"=>"your_user_name","api_key"=>"your_api_key")) |
43 | 39 | ``` |
44 | 40 |
|
45 | 41 | Note: your credentials will be saved within /YOUR_HOME_DIR/.plotly/.credentials |
46 | 42 |
|
47 | | -## Saving your endpoint configuration |
| 43 | +### Saving your endpoint configuration |
48 | 44 | ```julia |
49 | 45 | julia> Plotly.set_config_file(Dict("plotly_domain"=> "your_plotly_base_endpoint", "plotly_api_domain"=> "your_plotly_api_endpoint")) |
50 | 46 | ``` |
51 | 47 |
|
52 | 48 | Note: your configuration will be saved within /YOUR_HOME_DIR/.plotly/.config |
53 | 49 |
|
54 | | -## Plot && Open in browser |
55 | | -```julia |
56 | | -julia> Plotly.openurl(Plotly.plot(["z"=>rand(6,6)],["style"=>["type"=>"heatmap"]])) |
57 | | -START /bin/firefox "https://plot.ly/~astrieanna/0" |
58 | | -``` |
59 | | - |
60 | | -That last line is what the REPL prints out, |
61 | | -as a Firefox tab opens with the plot. |
62 | | -You can also just call `plot` by itself, and you'll get a String that's the url of your chart. |
63 | | - |
64 | | -## Style and Layout |
65 | | -```julia |
66 | | -julia> Plotly.style(["line"=>["color"=>"rgb(255,0,0)","width"=>10]]) |
67 | | -julia> Plotly.layout(["layout"=>["title"=>"Time Wasted"]]) |
68 | | -``` |
69 | | - |
70 | | -# Quick Plotting |
71 | | -## Functions and Polynomials |
72 | | -```julia |
73 | | -julia> Plotly.plot(abs) |
74 | | -julia> Plotly.plot([sqrt, log], ["left"=>10, "right"=>20, "step"=>0.1]) |
75 | | -julia> Plotly.plot() do x |
76 | | - savings = 3000 |
77 | | - income = x*1000 |
78 | | - expenses = x*800 |
79 | | - return savings+income-expenses |
80 | | - end |
81 | | -``` |
| 50 | +### Saving a plot to the cloud |
82 | 51 |
|
83 | | -You can now plot functions directly. |
84 | | -The first line shows how to plot the absolute value function, and the second line plots |
85 | | -the square root and logarithm functions, both from 10 to 20 at increments of 0.1. |
86 | | -The last line shows how to use Julia's `do` syntax to plot complicated anonymous functions. |
| 52 | +Use the `post` function to upload a local plot to the Plotly cloud: |
87 | 53 |
|
88 | | -```julia |
89 | | -julia> using Polynomial |
90 | | -julia> x = Poly([1,0]) |
91 | | -julia> Plotly.plot(3x^3 + 2x^2 - x + 1) |
92 | | -julia> Plotly.plot([x, 2x, 3x^2-x]) |
93 | 54 | ``` |
94 | | - |
95 | | -Using the Polynomial package, you can plot polynomials directly the same way as math functions. |
96 | | - |
97 | | -## DataFrames and TimeSeries |
98 | | -```julia |
99 | | -julia> using DataFrames |
100 | | -julia> df = readtable("height_vs_weight.csv") |
101 | | -julia> Plotly.plot(df, ["xs"=>:height, "ys"=>:weight]) |
| 55 | +> my_plot = plot([scatter(y=[1,2])]) |
| 56 | +> remote_plot = post(my_plot) |
| 57 | +Plotly.RemotePlot(URI(https://plot.ly/~malmaud/73)) |
102 | 58 | ``` |
103 | 59 |
|
104 | | -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. |
| 60 | +Visiting <https://plot.ly/~malmaud/73> in a browser will show the plot. |
105 | 61 |
|
106 | | -```julia |
107 | | -julia> using TimeSeries |
108 | | -julia> d = [date(2012,5,29):date(2013,5,29)] |
109 | | -julia> t = TimeArray(d, rand(length(d),2), ["foo","bar"]) |
110 | | -julia> Plotly.plot(t) |
111 | | -``` |
| 62 | +### Download a plot from the cloud |
112 | 63 |
|
113 | | -Using the TimeSeries package, you can plot them directly by passing a TimeArray argument. |
| 64 | +Use the `download` function with a remote plot object to download a plot stored on the Plotly cloud to a local `Plot` object: |
114 | 65 |
|
115 | | -## WAV Files |
116 | | -```julia |
117 | | -julia> using WAV |
118 | | -julia> Plotly.plot(wavread("filename.wav")) |
119 | 66 | ``` |
120 | | - |
121 | | -Using the WAV package, you can plot WAV files by passing a call to the `wavread` function. |
122 | | - |
123 | | -# Detailed Plotting |
124 | | -## Arrays and Dicts |
125 | | -```julia |
126 | | -julia> trace1 = Plotly.line([3x for x in 1:1000]) |
127 | | -julia> trace2 = Plotly.histogram([3x for x in 1:1000]) |
128 | | -julia> trace3 = Plotly.scatter([2x => 3x for x in 1:1000]) |
129 | | -julia> trace4 = Plotly.box([2x => 3x for x in 1:1000]) |
130 | | -julia |
| 67 | +local_plot = download(RemotePlot("https://plot.ly/~malmaud/73")) |
| 68 | +# or equivalently, local_plot = download_plot("https://plot.ly/~malmaud/73") |
131 | 69 | ``` |
132 | 70 |
|
133 | | -## Functions and Polynomials |
134 | | -```julia |
135 | | -julia> trace1 = Plotly.line(abs, ["left"=>10, "right"=>20, "step"=>0.1]) |
136 | | -julia> trace2 = Plotly.box(sin, ["left"=>10, "right"=>20, "step"=>0.1]) |
137 | | -julia> trace3 = Plotly.scatter(cos, ["left"=>10, "right"=>20, "step"=>0.1]) |
138 | | -julia> trace4 = Plotly.histogram(cos, ["left"=>10, "right"=>20, "step"=>0.1]) |
139 | | -julia> Plotly.plot([trace1, trace2, trace3, trace4]) |
140 | | - |
141 | | -julia> using Polynomial |
142 | | -julia> x = Poly([1,0]) |
143 | | -julia> trace1 = Plotly.line(3x^3 + 2x^2 - x + 1) |
144 | | -julia> trace2 = Plotly.histogram(3x^3 + 2x^2 - x + 1) |
145 | | -julia> Plotly.plot([trace1, trace2]) |
146 | | -``` |
147 | 71 |
|
148 | | -## DataFrames and TimeSeries |
149 | | -```julia |
150 | | -julia> using DataFrames |
151 | | -julia> df = readtable("height_vs_weight.csv") |
152 | | -julia> trace1 = Plotly.line(df, ["xs"=>:height, "ys"=>:weight]) |
153 | | -julia> trace2 = Plotly.scatter(df, ["xs"=>:height, "ys"=>:weight]) |
154 | | -julia> trace3 = Plotly.histogram(df, ["xs"=>:height]) |
155 | | -julia> trace4 = Plotly.box(df, ["ys"=>:weight]) |
156 | | -julia> Plotly.plot([trace1, trace2, trace3, trace4]) |
157 | | - |
158 | | -julia> using TimeSeries |
159 | | -julia> d = [date(2012,5,29):date(2013,5,29)] |
160 | | -julia> t = TimeArray(d, rand(length(d),2), ["foo","bar"]) |
161 | | -julia> trace1 = Plotly.line(t) |
162 | | -julia> trace2 = Plotly.scatter(t) |
163 | | -julia> trace3 = Plotly.box(t) |
164 | | -julia> trace4 = Plotly.histogram(t) |
165 | | -julia> Plotly.plot([trace1, trace2, trace3, trace4]) |
166 | | -``` |
| 72 | +### Acknowledgements |
| 73 | +[PlotlyJS.jl ](https://github.com/spencerlyon2/PlotlyJS.jl), which provides the large majority of the functionality of this package, is developed primarily by Spencer Lyon. |
167 | 74 |
|
168 | | -## WAV Files |
169 | | -```julia |
170 | | -julia> using WAV |
171 | | -julia> trace1 = Plotly.line(wavread("filename.wav")) |
172 | | -julia> trace2 = Plotly.histogram(wavread("filename.wav")) |
173 | | -julia> trace3 = Plotly.box(wavread("filename.wav")) |
174 | | -julia> trace4 = Plotly.scatter(wavread("filename.wav")) |
175 | | -julia> Plotly.plot([trace1, trace2, trace3, trace4]) |
176 | | -``` |
| 75 | +This package, which adds to PlotlyJS.jl the functionality for interacting with the Plotly cloud, is developed by Jon Malmaud and others. |
0 commit comments