-
Notifications
You must be signed in to change notification settings - Fork 9
/
plotly.m
89 lines (60 loc) · 2.78 KB
/
plotly.m
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
(* ::Package:: *)
(*Plotly v0.2*)
BeginPackage["Plotly`"];
Plotly::usage = "A package for plotting plot.ly graphs in Wolfram Mathematica"
Begin["`Private`"]
plotlyun="Mathematica";
plotlykey="u1ns4bx2df";
PlotlyLogin[plotlyunlogin_,plotlykeylogin_]:=Set[{plotlyun,plotlykey},{plotlyunlogin,plotlykeylogin}];
plotlyframed[d_]:=Hyperlink[Framed[Show[Import[StringJoin[StringReplace[d,{"\""->"","{"->"","}"->"","url"->"","message"~~__->"",Whitespace->"",","->"",":"->"","https"->"https:"}],".png"]],ImageSize->Large]],StringReplace[d,{"\""->"","{"->"","}"->"","url"->"","message"~~__->"",Whitespace->"",","->"",":"->"","https"->"https:"}]]
(* ::Input:: *)
(*"Cot[x] ne radi! Pojedina\[CHacek]ni graf Log[x] ne radi"*)
Options[Plotly]={PlotLabel->"a plot from the mathematica api"};
Plotly[f_,{x_,min_,max_},OptionsPattern[]]:=plotlyframed[URLExecute["https://plot.ly/clientresp",{"un"->plotlyun,"key"->plotlykey,"origin"->"plot","platform"->"mathematica",
"args"->StringReplace[
If[StringCount[ToString[f],","]>0,
StringJoin[
Table[
StringJoin["[{\"x\":",
StringReplace[
ToString[
Table[x,{x,min,max,.1}]],
{"{"->"[","}"->"]",".,"->".0,",".}"->".0]","Indeterminate"->"null",".e,"->".0,","e,"->",","e}"->"]",".e}"->".0]",".e"->".0e"}]
,",\"y\":",
StringReplace[
ToString[
NumberForm[Table[f,{x,min,max,.1}][[All,i]],NumberFormat->(Row[{#1,"e",#3}]&)]],
{"}"->"]",".,"->".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","{"->"["}]
,",\"type\":\"scatter\"},"]
,{i,StringCount[ToString[f],","]+1}],
"]"],
StringJoin[
StringJoin["[{\"x\":",
StringReplace[
ToString[
Table[x,{x,min,max,.1}]],
{"{"->"[","}"->"]",".,"->".0,",".}"->".0]","Indeterminate"->"null",".e,"->".0,","e,"->",","e}"->"]",".e}"->".0]",".e"->".0e"}]
,",\"y\":",
StringReplace[
ToString[
NumberForm[Table[f,{x,min,max,.1}],NumberFormat->(Row[{#1,"e",#3}]&)]]
,
{":{"->":[",":{"->"[","},\""->"],\"","}{"->"},{",".,"->".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"}]
,",\"type\":\"scatter\"}"]
,"]"]]
,{",[{"->",{","},]"->"}]","\"y\":{"->"\"y\":[","nullndeterminat"->"null, null"}],
"kwargs"->StringJoin["{
\"filename\": \"mathematicaplot\",
\"fileopt\": \"new\",
\"style\": {
\"type\": \"scatter\"
},
\"traces\": [0,1,2],
\"layout\": {
\"title\": \"","a plot from the mathematica api v0.2","\"
},
\"world_readable\": true
}"]
},"Method"->"POST"]]
End[]
EndPackage[]