Skip to content

Commit ff41368

Browse files
committed
Merge branch 'master' into fix_init_notebook_mode
2 parents 742f944 + fbf3b74 commit ff41368

File tree

10 files changed

+418
-170
lines changed

10 files changed

+418
-170
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44

55
## [Unreleased]
66

7+
## [1.9.13] - 2016-05-19
8+
### Fixed
9+
- Fixed issue in offline mode related to the inability to reload plotly.js on page refresh and extra init_notebook_mode calls.
10+
11+
## [1.9.12] - 2016-05-16
12+
### Added
13+
SSL support for streaming.
14+
715
## [1.9.11] - 2016-05-02
816
### Added
917
- The FigureFactory can now create scatter plot matrices with `.create_scatterplotmatrix`. Check it out with:

contributing.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,23 @@ You're *strongly* encouraged to write tests that check your added functionality.
136136

137137
When you write a new test anywhere under the `tests` directory, if your PR gets accepted, that test will run in a virtual machine to ensure that future changes don't break your contributions!
138138

139+
#### Publishing to Pip
140+
141+
You'll need the credentials file `~/.pypirc`. Request access from @theengineear and @chriddyp. Then, from inside the repository:
142+
143+
```
144+
(plotly.py) $ git checkout master
145+
(plotly.py) $ git stash
146+
(plotly.py) $ git pull origin master
147+
(plotly.py) $ python setup.py sdist upload # upload to pip
148+
```
149+
150+
After it has uploaded, move to another directly and double+triple check that you are able to upgrade ok:
151+
```
152+
$ pip install plotly --upgrade
153+
```
154+
155+
And ask one of your friends to do it too. Our tests should catch any issues, but you never know.
156+
157+
139158
<3 Team Plotly

plotly/graph_reference/default-schema.json

Lines changed: 132 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,8 @@
712712
"mollweide",
713713
"hammer",
714714
"transverse mercator",
715-
"albers usa"
715+
"albers usa",
716+
"winkel tripel"
716717
]
717718
}
718719
},
@@ -838,6 +839,114 @@
838839
false
839840
]
840841
},
842+
"images": {
843+
"items": {
844+
"image": {
845+
"layer": {
846+
"description": "Specifies whether images are drawn below or above traces. When `xref` and `yref` are both set to `paper`, image is drawn below the entire plot area.",
847+
"dflt": "above",
848+
"role": "info",
849+
"valType": "enumerated",
850+
"values": [
851+
"below",
852+
"above"
853+
]
854+
},
855+
"opacity": {
856+
"description": "Sets the opacity of the image.",
857+
"dflt": 1,
858+
"max": 1,
859+
"min": 0,
860+
"role": "info",
861+
"valType": "number"
862+
},
863+
"role": "object",
864+
"sizex": {
865+
"description": "Sets the image container size horizontally. The image will be sized based on the `position` value. When `xref` is set to `paper`, units are sized relative to the plot width.",
866+
"dflt": 0,
867+
"role": "info",
868+
"valType": "number"
869+
},
870+
"sizey": {
871+
"description": "Sets the image container size vertically. The image will be sized based on the `position` value. When `yref` is set to `paper`, units are sized relative to the plot height.",
872+
"dflt": 0,
873+
"role": "info",
874+
"valType": "number"
875+
},
876+
"sizing": {
877+
"description": "Specifies which dimension of the image to constrain.",
878+
"dflt": "contain",
879+
"role": "info",
880+
"valType": "enumerated",
881+
"values": [
882+
"fill",
883+
"contain",
884+
"stretch"
885+
]
886+
},
887+
"source": {
888+
"description": "Specifies the URL of the image to be used. The URL must be accessible from the domain where the plot code is run, and can be either relative or absolute.",
889+
"role": "info",
890+
"valType": "string"
891+
},
892+
"x": {
893+
"description": "Sets the image's x position. When `xref` is set to `paper`, units are sized relative to the plot height. See `xref` for more info",
894+
"dflt": 0,
895+
"role": "info",
896+
"valType": "number"
897+
},
898+
"xanchor": {
899+
"description": "Sets the anchor for the x position",
900+
"dflt": "left",
901+
"role": "info",
902+
"valType": "enumerated",
903+
"values": [
904+
"left",
905+
"center",
906+
"right"
907+
]
908+
},
909+
"xref": {
910+
"description": "Sets the images's x coordinate axis. If set to a x axis id (e.g. *x* or *x2*), the `x` position refers to an x data coordinate If set to *paper*, the `x` position refers to the distance from the left of plot in normalized coordinates where *0* (*1*) corresponds to the left (right).",
911+
"dflt": "paper",
912+
"role": "info",
913+
"valType": "enumerated",
914+
"values": [
915+
"paper",
916+
"/^x([2-9]|[1-9][0-9]+)?$/"
917+
]
918+
},
919+
"y": {
920+
"description": "Sets the image's y position. When `yref` is set to `paper`, units are sized relative to the plot height. See `yref` for more info",
921+
"dflt": 0,
922+
"role": "info",
923+
"valType": "number"
924+
},
925+
"yanchor": {
926+
"description": "Sets the anchor for the y position.",
927+
"dflt": "top",
928+
"role": "info",
929+
"valType": "enumerated",
930+
"values": [
931+
"top",
932+
"middle",
933+
"bottom"
934+
]
935+
},
936+
"yref": {
937+
"description": "Sets the images's y coordinate axis. If set to a y axis id (e.g. *y* or *y2*), the `y` position refers to a y data coordinate. If set to *paper*, the `y` position refers to the distance from the bottom of the plot in normalized coordinates where *0* (*1*) corresponds to the bottom (top).",
938+
"dflt": "paper",
939+
"role": "info",
940+
"valType": "enumerated",
941+
"values": [
942+
"paper",
943+
"/^y([2-9]|[1-9][0-9]+)?$/"
944+
]
945+
}
946+
}
947+
},
948+
"role": "object"
949+
},
841950
"legend": {
842951
"bgcolor": {
843952
"description": "Sets the legend background color.",
@@ -877,6 +986,16 @@
877986
"valType": "number"
878987
}
879988
},
989+
"orientation": {
990+
"description": "Sets the orientation of the legend.",
991+
"dflt": "v",
992+
"role": "info",
993+
"valType": "enumerated",
994+
"values": [
995+
"v",
996+
"h"
997+
]
998+
},
880999
"role": "object",
8811000
"tracegroupgap": {
8821001
"description": "Sets the amount of vertical space (in px) between legend groups.",
@@ -6018,14 +6137,15 @@
60186137
"valType": "number"
60196138
},
60206139
"barmode": {
6021-
"description": "Determines how bars at the same location coordinate are displayed on the graph. With *stack*, the bars are stacked on top of one another With *group*, the bars are plotted next to one another centered around the shared location. With *overlay*, the bars are plotted over one another, you might need to an *opacity* to see multiple bars.",
6140+
"description": "Determines how bars at the same location coordinate are displayed on the graph. With *stack*, the bars are stacked on top of one another With *relative*, the bars are stacked on top of one another, with negative values below the axis, positive values above With *group*, the bars are plotted next to one another centered around the shared location. With *overlay*, the bars are plotted over one another, you might need to an *opacity* to see multiple bars.",
60226141
"dflt": "group",
60236142
"role": "info",
60246143
"valType": "enumerated",
60256144
"values": [
60266145
"stack",
60276146
"group",
6028-
"overlay"
6147+
"overlay",
6148+
"relative"
60296149
]
60306150
},
60316151
"barnorm": {
@@ -9298,14 +9418,15 @@
92989418
"valType": "number"
92999419
},
93009420
"barmode": {
9301-
"description": "Determines how bars at the same location coordinate are displayed on the graph. With *stack*, the bars are stacked on top of one another With *group*, the bars are plotted next to one another centered around the shared location. With *overlay*, the bars are plotted over one another, you might need to an *opacity* to see multiple bars.",
9421+
"description": "Determines how bars at the same location coordinate are displayed on the graph. With *stack*, the bars are stacked on top of one another With *relative*, the bars are stacked on top of one another, with negative values below the axis, positive values above With *group*, the bars are plotted next to one another centered around the shared location. With *overlay*, the bars are plotted over one another, you might need to an *opacity* to see multiple bars.",
93029422
"dflt": "group",
93039423
"role": "info",
93049424
"valType": "enumerated",
93059425
"values": [
93069426
"stack",
93079427
"group",
9308-
"overlay"
9428+
"overlay",
9429+
"relative"
93099430
]
93109431
},
93119432
"barnorm": {
@@ -15156,6 +15277,12 @@
1515615277
},
1515715278
"scattergl": {
1515815279
"attributes": {
15280+
"connectgaps": {
15281+
"description": "Determines whether or not gaps (i.e. {nan} or missing values) in the provided data arrays are connected.",
15282+
"dflt": false,
15283+
"role": "info",
15284+
"valType": "boolean"
15285+
},
1515915286
"dx": {
1516015287
"description": "Sets the x coordinate step. See `x0` for more info.",
1516115288
"dflt": 1,

plotly/offline/offline.py

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414

1515
import plotly
1616
from plotly import tools, utils
17-
from plotly.exceptions import PlotlyError
18-
1917

2018
try:
2119
import IPython
20+
from IPython.display import HTML, display
2221
_ipython_imported = True
2322
except ImportError:
2423
_ipython_imported = False
@@ -30,9 +29,6 @@
3029
_matplotlib_imported = False
3130

3231

33-
__PLOTLY_OFFLINE_INITIALIZED = False
34-
35-
3632
def download_plotlyjs(download_url):
3733
warnings.warn('''
3834
`download_plotlyjs` is deprecated and will be removed in the
@@ -50,27 +46,39 @@ def get_plotlyjs():
5046

5147
def init_notebook_mode():
5248
"""
53-
Initialize Plotly Offline mode in an IPython Notebook.
54-
Run this function at the start of an IPython notebook
55-
to load the necessary javascript files for creating
56-
Plotly graphs with plotly.offline.iplot.
49+
Initialize plotly.js in the browser if it hasn't been loaded into the DOM
50+
yet. This is an idempotent method and can and should be called from any
51+
offline methods that require plotly.js to be loaded into the notebook dom.
5752
"""
58-
if not tools._ipython_imported:
53+
warnings.warn('''
54+
`init_notebook_mode` is deprecated and will be removed in the
55+
next release. Notebook mode is now automatically initialized when
56+
notebook methods are invoked, so it is no
57+
longer necessary to manually initialize.
58+
''', DeprecationWarning)
59+
60+
if not _ipython_imported:
5961
raise ImportError('`iplot` can only run inside an IPython Notebook.')
60-
from IPython.display import HTML, display
6162

6263
global __PLOTLY_OFFLINE_INITIALIZED
6364
# ALways display the script so that init_notebook_mode is idempotent
64-
display(HTML("<script type='text/javascript'>" +
65-
"define('plotly', function(require, exports, module) {" +
66-
get_plotlyjs() +
67-
"});" +
68-
"require(['plotly'], function(Plotly) {" +
69-
"window.Plotly = Plotly;" +
70-
"});" +
71-
"</script>"))
72-
__PLOTLY_OFFLINE_INITIALIZED = True
65+
script_inject = (
66+
''
67+
'<script type=\'text/javascript\'>'
68+
'if(!window.Plotly){{'
69+
'define(\'plotly\', function(require, exports, module) {{'
70+
'{script}'
71+
'}});'
72+
'require([\'plotly\'], function(Plotly) {{'
73+
'console.log(Plotly);'
74+
'window.Plotly = Plotly;'
75+
'}});'
76+
'}}'
77+
'</script>'
78+
'').format(script=get_plotlyjs())
7379

80+
display(HTML(script_inject))
81+
__PLOTLY_OFFLINE_INITIALIZED = True
7482

7583
def _plot_html(figure_or_data, show_link, link_text,
7684
validate, default_width, default_height, global_requirejs):
@@ -171,25 +179,11 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
171179
172180
Example:
173181
```
174-
from plotly.offline import init_notebook_mode, iplot
175-
init_notebook_mode()
182+
from plotly.offline import iplot
176183
177184
iplot([{'x': [1, 2, 3], 'y': [5, 2, 7]}])
178185
```
179186
"""
180-
if not __PLOTLY_OFFLINE_INITIALIZED:
181-
raise PlotlyError('\n'.join([
182-
'Plotly Offline mode has not been initialized in this notebook. '
183-
'Run: ',
184-
'',
185-
'import plotly',
186-
'plotly.offline.init_notebook_mode() '
187-
'# run at the start of every ipython notebook',
188-
]))
189-
if not tools._ipython_imported:
190-
raise ImportError('`iplot` can only run inside an IPython Notebook.')
191-
192-
from IPython.display import HTML, display
193187

194188
plot_html, plotdivid, width, height = _plot_html(
195189
figure_or_data, show_link, link_text, validate,
@@ -421,11 +415,9 @@ def iplot_mpl(mpl_fig, resize=False, strip_style=False,
421415
422416
Example:
423417
```
424-
from plotly.offline import init_notebook_mode, iplot_mpl
418+
from plotly.offline import iplot_mpl
425419
import matplotlib.pyplot as plt
426420
427-
init_notebook_mode()
428-
429421
fig = plt.figure()
430422
x = [10, 15, 20, 25, 30]
431423
y = [100, 250, 200, 150, 300]
@@ -434,6 +426,7 @@ def iplot_mpl(mpl_fig, resize=False, strip_style=False,
434426
iplot_mpl(fig)
435427
```
436428
"""
429+
437430
plotly_plot = tools.mpl_to_plotly(mpl_fig, resize, strip_style, verbose)
438431
return iplot(plotly_plot, show_link, link_text, validate)
439432

@@ -454,10 +447,9 @@ def enable_mpl_offline(resize=False, strip_style=False,
454447
455448
Example:
456449
```
457-
from plotly.offline import init_notebook_mode, enable_mpl_offline
450+
from plotly.offline import enable_mpl_offline
458451
import matplotlib.pyplot as plt
459452
460-
init_notebook_mode()
461453
enable_mpl_offline()
462454
463455
fig = plt.figure()
@@ -467,8 +459,8 @@ def enable_mpl_offline(resize=False, strip_style=False,
467459
fig
468460
```
469461
"""
470-
if not __PLOTLY_OFFLINE_INITIALIZED:
471-
init_notebook_mode()
462+
init_notebook_mode()
463+
472464
ip = IPython.core.getipython.get_ipython()
473465
formatter = ip.display_formatter.formatters['text/html']
474466
formatter.for_type(matplotlib.figure.Figure,

0 commit comments

Comments
 (0)