├── README.md ├── plotly.m └── plotly.wl /README.md: -------------------------------------------------------------------------------- 1 | # PlotlyMathematica 2 | A package for creating plot.ly graphs in Wolfram Mathematica 3 | 4 | ![Plotly-Mathematica Plot](http://cl.ly/XybJ/Image%202014-10-11%20at%2012.15.25%20pm.png) 5 | 6 | 7 | ## Getting started 8 | 1. Install package (File->Install) and select plotly.m as the source 9 | 2. Type Needs["Plotly`"] in your notebook. 10 | 3. The syntax matches native Plot function, just type Plotly[yourfunction,{x,min,max}] to make your first plot. 11 | 4. (optional) type PlotlyLogin[username,APIKey] to plot under your Plotly account 12 | 13 | ## Version 0.2 (current) 14 | - bugfixes & optimization 15 | - proper package declaration 16 | - out of the box plotting, no need to input user/pass 17 | 18 | ## Future releases 19 | ### Version 0.3 (in the works) 20 | - support for older versions of Mathematica (replace URLExecute with JSON) 21 | - support for styling 22 | - code rewrite 23 | 24 | ### Version 0.4+ (planned) 25 | - support for discrete plots, histograms, heatmaps, data streams, 3d plots, etc. 26 | 27 | ## Legacy releases 28 | ### Version 0.1 (legacy) 29 | - replicates the functionality of the the native Plot function within Mathematica 30 | - works only in Mathematica 10 31 | - no support for styling within Mathematica (PlotStyle, PlotLabel, AxesLabel, etc.) 32 | - no support for imaginary units 33 | - indeterminate function values are set to 0 34 | 35 | -------------------------------------------------------------------------------- /plotly.m: -------------------------------------------------------------------------------- 1 | (* ::Package:: *) 2 | 3 | (*Plotly v0.2*) 4 | 5 | 6 | BeginPackage["Plotly`"]; 7 | Plotly::usage = "A package for plotting plot.ly graphs in Wolfram Mathematica" 8 | 9 | 10 | Begin["`Private`"] 11 | 12 | 13 | plotlyun="Mathematica"; 14 | 15 | 16 | plotlykey="u1ns4bx2df"; 17 | 18 | 19 | PlotlyLogin[plotlyunlogin_,plotlykeylogin_]:=Set[{plotlyun,plotlykey},{plotlyunlogin,plotlykeylogin}]; 20 | 21 | 22 | plotlyframed[d_]:=Hyperlink[Framed[Show[Import[StringJoin[StringReplace[d,{"\""->"","{"->"","}"->"","url"->"","message"~~__->"",Whitespace->"",","->"",":"->"","https"->"https:"}],".png"]],ImageSize->Large]],StringReplace[d,{"\""->"","{"->"","}"->"","url"->"","message"~~__->"",Whitespace->"",","->"",":"->"","https"->"https:"}]] 23 | 24 | 25 | (* ::Input:: *) 26 | (*"Cot[x] ne radi! Pojedina\[CHacek]ni graf Log[x] ne radi"*) 27 | 28 | 29 | Options[Plotly]={PlotLabel->"a plot from the mathematica api"}; 30 | 31 | 32 | Plotly[f_,{x_,min_,max_},OptionsPattern[]]:=plotlyframed[URLExecute["https://plot.ly/clientresp",{"un"->plotlyun,"key"->plotlykey,"origin"->"plot","platform"->"mathematica", 33 | "args"->StringReplace[ 34 | If[StringCount[ToString[f],","]>0, 35 | 36 | StringJoin[ 37 | Table[ 38 | StringJoin["[{\"x\":", 39 | StringReplace[ 40 | ToString[ 41 | Table[x,{x,min,max,.1}]], 42 | {"{"->"[","}"->"]",".,"->".0,",".}"->".0]","Indeterminate"->"null",".e,"->".0,","e,"->",","e}"->"]",".e}"->".0]",".e"->".0e"}] 43 | ,",\"y\":", 44 | StringReplace[ 45 | ToString[ 46 | NumberForm[Table[f,{x,min,max,.1}][[All,i]],NumberFormat->(Row[{#1,"e",#3}]&)]], 47 | {"}"->"]",".,"->".0,",".}"->".0]",","~~ShortestMatch[___]~~"I"->", null","{"~~ShortestMatch[___]~~"I"->"[null","Indeterminate"->"null","-Infinity"->"null","Infinity"->"null","ComplexInfinity"->"null",".e,"->".0,","e,"->",","e}"->"]",".e}"->".0]",".e"->".0e","0.e"->"0.0","{"->"["}] 48 | ,",\"type\":\"scatter\"},"] 49 | ,{i,StringCount[ToString[f],","]+1}], 50 | "]"], 51 | StringJoin[ 52 | 53 | StringJoin["[{\"x\":", 54 | StringReplace[ 55 | ToString[ 56 | Table[x,{x,min,max,.1}]], 57 | {"{"->"[","}"->"]",".,"->".0,",".}"->".0]","Indeterminate"->"null",".e,"->".0,","e,"->",","e}"->"]",".e}"->".0]",".e"->".0e"}] 58 | ,",\"y\":", 59 | StringReplace[ 60 | ToString[ 61 | NumberForm[Table[f,{x,min,max,.1}],NumberFormat->(Row[{#1,"e",#3}]&)]] 62 | , 63 | 64 | {":{"->":[",":{"->"[","},\""->"],\"","}{"->"},{",".,"->".0,",".}"->".0]",","~~ShortestMatch[___]~~"I"->", null","{"~~ShortestMatch[___]~~"I"->"[null","Indeterminate"->"null","ComplexInfinity"->"null","-Infinity"->"null","Infinity"->"null",".e,"->".0,","e,"->",","e}"->"]",".e}"->".0]",".e"->".0e","0.e"->"0.0"}] 65 | 66 | ,",\"type\":\"scatter\"}"] 67 | 68 | ,"]"]] 69 | 70 | ,{",[{"->",{","},]"->"}]","\"y\":{"->"\"y\":[","nullndeterminat"->"null, null"}], 71 | "kwargs"->StringJoin["{ 72 | \"filename\": \"mathematicaplot\", 73 | \"fileopt\": \"new\", 74 | \"style\": { 75 | \"type\": \"scatter\" 76 | }, 77 | \"traces\": [0,1,2], 78 | \"layout\": { 79 | \"title\": \"","a plot from the mathematica api v0.2","\" 80 | }, 81 | \"world_readable\": true 82 | }"] 83 | },"Method"->"POST"]] 84 | 85 | 86 | End[] 87 | 88 | 89 | EndPackage[] 90 | -------------------------------------------------------------------------------- /plotly.wl: -------------------------------------------------------------------------------- 1 | (* ::Package:: *) 2 | 3 | (*Plotly v0.2*) 4 | 5 | 6 | BeginPackage["Plotly`"]; 7 | Plotly::usage = "A package for plotting plot.ly graphs in Wolfram Mathematica" 8 | 9 | 10 | Begin["`Private`"] 11 | 12 | 13 | plotlyun="Mathematica"; 14 | 15 | 16 | plotlykey="u1ns4bx2df"; 17 | 18 | 19 | PlotlyLogin[plotlyunlogin_,plotlykeylogin_]:=Set[{plotlyun,plotlykey},{plotlyunlogin,plotlykeylogin}]; 20 | 21 | 22 | plotlyframed[d_]:=Hyperlink[Framed[Show[Import[StringJoin[StringReplace[d,{"\""->"","{"->"","}"->"","url"->"","message"~~__->"",Whitespace->"",","->"",":"->"","https"->"https:"}],".png"]],ImageSize->Large]],StringReplace[d,{"\""->"","{"->"","}"->"","url"->"","message"~~__->"",Whitespace->"",","->"",":"->"","https"->"https:"}]] 23 | 24 | 25 | (* ::Input:: *) 26 | (*"Cot[x] ne radi! Pojedina\[CHacek]ni graf Log[x] ne radi"*) 27 | 28 | 29 | Options[Plotly]={PlotLabel->"a plot from the mathematica api"}; 30 | 31 | 32 | Plotly[f_,{x_,min_,max_},OptionsPattern[]]:=plotlyframed[URLExecute["https://plot.ly/clientresp",{"un"->plotlyun,"key"->plotlykey,"origin"->"plot","platform"->"mathematica", 33 | "args"->StringReplace[ 34 | If[StringCount[ToString[f],","]>0, 35 | 36 | StringJoin[ 37 | Table[ 38 | StringJoin["[{\"x\":", 39 | StringReplace[ 40 | ToString[ 41 | Table[x,{x,min,max,.1}]], 42 | {"{"->"[","}"->"]",".,"->".0,",".}"->".0]","Indeterminate"->"null",".e,"->".0,","e,"->",","e}"->"]",".e}"->".0]",".e"->".0e"}] 43 | ,",\"y\":", 44 | StringReplace[ 45 | ToString[ 46 | NumberForm[Table[f,{x,min,max,.1}][[All,i]],NumberFormat->(Row[{#1,"e",#3}]&)]], 47 | {"}"->"]",".,"->".0,",".}"->".0]",","~~ShortestMatch[___]~~"I"->", null","{"~~ShortestMatch[___]~~"I"->"[null","Indeterminate"->"null","-Infinity"->"null","Infinity"->"null","ComplexInfinity"->"null",".e,"->".0,","e,"->",","e}"->"]",".e}"->".0]",".e"->".0e","0.e"->"0.0","{"->"["}] 48 | ,",\"type\":\"scatter\"},"] 49 | ,{i,StringCount[ToString[f],","]+1}], 50 | "]"], 51 | StringJoin[ 52 | 53 | StringJoin["[{\"x\":", 54 | StringReplace[ 55 | ToString[ 56 | Table[x,{x,min,max,.1}]], 57 | {"{"->"[","}"->"]",".,"->".0,",".}"->".0]","Indeterminate"->"null",".e,"->".0,","e,"->",","e}"->"]",".e}"->".0]",".e"->".0e"}] 58 | ,",\"y\":", 59 | StringReplace[ 60 | ToString[ 61 | NumberForm[Table[f,{x,min,max,.1}],NumberFormat->(Row[{#1,"e",#3}]&)]] 62 | , 63 | 64 | {":{"->":[",":{"->"[","},\""->"],\"","}{"->"},{",".,"->".0,",".}"->".0]",","~~ShortestMatch[___]~~"I"->", null","{"~~ShortestMatch[___]~~"I"->"[null","Indeterminate"->"null","ComplexInfinity"->"null","-Infinity"->"null","Infinity"->"null",".e,"->".0,","e,"->",","e}"->"]",".e}"->".0]",".e"->".0e","0.e"->"0.0"}] 65 | 66 | ,",\"type\":\"scatter\"}"] 67 | 68 | ,"]"]] 69 | 70 | ,{",[{"->",{","},]"->"}]","\"y\":{"->"\"y\":[","nullndeterminat"->"null, null"}], 71 | "kwargs"->StringJoin["{ 72 | \"filename\": \"mathematicaplot\", 73 | \"fileopt\": \"new\", 74 | \"style\": { 75 | \"type\": \"scatter\" 76 | }, 77 | \"traces\": [0,1,2], 78 | \"layout\": { 79 | \"title\": \"","a plot from the mathematica api v0.2","\" 80 | }, 81 | \"world_readable\": true 82 | }"] 83 | },"Method"->"POST"]] 84 | 85 | 86 | End[] 87 | 88 | 89 | EndPackage[] 90 | --------------------------------------------------------------------------------