Skip to content

Commit 71d3cc8

Browse files
committed
Merge branch 'master' into etienne-factories
Conflicts: plotly/graph_objs/__init__.py plotly/graph_objs/graph_objs.py
2 parents 686b6c5 + 8978802 commit 71d3cc8

File tree

12 files changed

+106
-98
lines changed

12 files changed

+106
-98
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Now you can download, design, and upload Plotly figures--all from Python.
1111

1212
###Where to go from here
1313

14-
* [Get started with our guide book!](http://nbviewer.ipython.org/github/plotly/python-user-guide/blob/master/s0_getting-started/s0_getting-started.ipynb)
14+
* [Get started with our guide book!](https://plot.ly/python/user-guide/)
1515

1616
* Official docs: [https://plot.ly/python](https://plot.ly/python)
1717

plotly/graph_objs/__init__.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
This package imports definitions for all of Plotly's graph objects. For more
66
information, run help(Obj) on any of the following objects defined here.
77
8+
The reason for the package graph_objs and the module graph_objs is to provide
9+
a clearer API for users.
810
911
"""
10-
from __future__ import absolute_import
11-
12-
from plotly.graph_objs.graph_objs import * # import everything...
13-
14-
from plotly.graph_objs.graph_objs_tools import OBJ_MAP
15-
16-
__all__ = [name for name in OBJ_MAP # ... but, only expose certain objects
17-
if name not in ['PlotlyList', 'PlotlyDict', 'PlotlyTrace']]
12+
from . graph_objs import (
13+
Data, Annotations, Area, Bar, Box, Contour, Heatmap, Histogram,
14+
Histogram2d, Histogram2dContour, Scatter, Annotation, AngularAxis,
15+
ColorBar, Contours, ErrorX, ErrorY, Figure, Font, Layout, Legend,
16+
Line, Margin, Marker, RadialAxis, Stream, Trace, XAxis, XBins, YAxis,
17+
YBins
18+
)

plotly/graph_objs/graph_objs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
else:
3939
from collections import OrderedDict
4040

41+
__all__ = None
42+
4143

4244
# (1) Make primitive graph objects
4345
class PlotlyList(list):

plotly/matplotlylib/renderer.py

Lines changed: 81 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212

1313
from . mplexporter import Renderer
1414
from . import mpltools
15-
from plotly.graph_objs import *
16-
15+
import plotly.graph_objs as go
1716

1817

1918
# Warning format
20-
def warning_on_one_line(message, category, filename, lineno, file=None, line=None):
21-
return '%s:%s: %s:\n\n%s\n\n' % (filename, lineno, category.__name__, message)
19+
def warning_on_one_line(msg, category, filename, lineno, file=None, line=None):
20+
return '%s:%s: %s:\n\n%s\n\n' % (filename, lineno, category.__name__, msg)
2221
warnings.formatwarning = warning_on_one_line
2322

23+
2424
class PlotlyRenderer(Renderer):
2525
"""A renderer class inheriting from base for rendering mpl plots in plotly.
2626
@@ -48,7 +48,7 @@ def __init__(self):
4848
All class attributes are listed here in the __init__ method.
4949
5050
"""
51-
self.plotly_fig = Figure(data=Data(), layout=Layout())
51+
self.plotly_fig = go.Figure()
5252
self.mpl_fig = None
5353
self.current_mpl_ax = None
5454
self.bar_containers = None
@@ -76,17 +76,19 @@ def open_figure(self, fig, props):
7676
"""
7777
self.msg += "Opening figure\n"
7878
self.mpl_fig = fig
79-
self.plotly_fig['layout'] = Layout(
80-
width=int(props['figwidth']*props['dpi']),
81-
height=int(props['figheight']*props['dpi']),
79+
self.plotly_fig['layout'] = go.Layout(
80+
width=int(props['figwidth'] * props['dpi']),
81+
height=int(props['figheight'] * props['dpi']),
8282
autosize=False,
8383
hovermode='closest')
8484
self.mpl_x_bounds, self.mpl_y_bounds = mpltools.get_axes_bounds(fig)
85-
margin = Margin(
86-
l=int(self.mpl_x_bounds[0]*self.plotly_fig['layout']['width']),
87-
r=int((1-self.mpl_x_bounds[1])*self.plotly_fig['layout']['width']),
88-
t=int((1-self.mpl_y_bounds[1])*self.plotly_fig['layout']['height']),
89-
b=int(self.mpl_y_bounds[0]*self.plotly_fig['layout']['height']),
85+
margin = go.Margin(
86+
l=int(self.mpl_x_bounds[0] * self.plotly_fig['layout']['width']),
87+
r=int(
88+
(1-self.mpl_x_bounds[1]) * self.plotly_fig['layout']['width']),
89+
t=int((1-self.mpl_y_bounds[1]) * self.plotly_fig['layout'][
90+
'height']),
91+
b=int(self.mpl_y_bounds[0] * self.plotly_fig['layout']['height']),
9092
pad=0)
9193
self.plotly_fig['layout']['margin'] = margin
9294

@@ -145,19 +147,20 @@ def open_axes(self, ax, props):
145147
self.current_bars = []
146148
self.axis_ct += 1
147149
# set defaults in axes
148-
xaxis = XAxis(
150+
xaxis = go.XAxis(
149151
anchor='y{0}'.format(self.axis_ct),
150152
zeroline=False,
151153
ticks='inside')
152-
yaxis = YAxis(
154+
yaxis = go.YAxis(
153155
anchor='x{0}'.format(self.axis_ct),
154156
zeroline=False,
155157
ticks='inside')
156158
# update defaults with things set in mpl
157-
mpl_xaxis, mpl_yaxis = mpltools.prep_xy_axis(ax=ax,
158-
props=props,
159-
x_bounds=self.mpl_x_bounds,
160-
y_bounds=self.mpl_y_bounds)
159+
mpl_xaxis, mpl_yaxis = mpltools.prep_xy_axis(
160+
ax=ax,
161+
props=props,
162+
x_bounds=self.mpl_x_bounds,
163+
y_bounds=self.mpl_y_bounds)
161164
xaxis.update(mpl_xaxis)
162165
yaxis.update(mpl_yaxis)
163166
bottom_spine = mpltools.get_spine_visible(ax, 'bottom')
@@ -169,7 +172,6 @@ def open_axes(self, ax, props):
169172
xaxis['showline'] = bottom_spine
170173
yaxis['showline'] = top_spine
171174

172-
173175
# put axes in our figure
174176
self.plotly_fig['layout']['xaxis{0}'.format(self.axis_ct)] = xaxis
175177
self.plotly_fig['layout']['yaxis{0}'.format(self.axis_ct)] = yaxis
@@ -216,15 +218,15 @@ def draw_bar(self, coll):
216218
widths = [bar_props['x1'] - bar_props['x0'] for bar_props in trace]
217219
heights = [bar_props['y1'] - bar_props['y0'] for bar_props in trace]
218220
vertical = abs(
219-
sum(widths[0]-widths[iii] for iii in range(len(widths)))
221+
sum(widths[0] - widths[iii] for iii in range(len(widths)))
220222
) < tol
221223
horizontal = abs(
222-
sum(heights[0]-heights[iii] for iii in range(len(heights)))
224+
sum(heights[0] - heights[iii] for iii in range(len(heights)))
223225
) < tol
224226
if vertical and horizontal:
225227
# Check for monotonic x. Can't both be true!
226228
x_zeros = [bar_props['x0'] for bar_props in trace]
227-
if all((x_zeros[iii+1] > x_zeros[iii]
229+
if all((x_zeros[iii + 1] > x_zeros[iii]
228230
for iii in range(len(x_zeros[:-1])))):
229231
orientation = 'v'
230232
else:
@@ -242,9 +244,9 @@ def draw_bar(self, coll):
242244
# check if we're stacked or not...
243245
for old, new in zip(old_heights, new_heights):
244246
if abs(old - new) > tol:
245-
self.plotly_fig['layout']['barmode']='stack'
246-
self.plotly_fig['layout']['hovermode']='x'
247-
x = [bar['x0']+(bar['x1']-bar['x0'])/2 for bar in trace]
247+
self.plotly_fig['layout']['barmode'] = 'stack'
248+
self.plotly_fig['layout']['hovermode'] = 'x'
249+
x = [bar['x0'] + (bar['x1'] - bar['x0']) / 2 for bar in trace]
248250
y = [bar['y1'] for bar in trace]
249251
bar_gap = mpltools.get_bar_gap([bar['x0'] for bar in trace],
250252
[bar['x1'] for bar in trace])
@@ -257,21 +259,22 @@ def draw_bar(self, coll):
257259
# check if we're stacked or not...
258260
for old, new in zip(old_rights, new_rights):
259261
if abs(old - new) > tol:
260-
self.plotly_fig['layout']['barmode']='stack'
261-
self.plotly_fig['layout']['hovermode']='y'
262+
self.plotly_fig['layout']['barmode'] = 'stack'
263+
self.plotly_fig['layout']['hovermode'] = 'y'
262264
x = [bar['x1'] for bar in trace]
263-
y = [bar['y0']+(bar['y1']-bar['y0'])/2 for bar in trace]
265+
y = [bar['y0'] + (bar['y1'] - bar['y0']) / 2 for bar in trace]
264266
bar_gap = mpltools.get_bar_gap([bar['y0'] for bar in trace],
265267
[bar['y1'] for bar in trace])
266-
bar = Bar(orientation=orientation,
267-
x=x,
268-
y=y,
269-
xaxis='x{0}'.format(self.axis_ct),
270-
yaxis='y{0}'.format(self.axis_ct),
271-
opacity=trace[0]['alpha'], # TODO: get all alphas if array?
272-
marker=Marker(
273-
color=trace[0]['facecolor'], # TODO: get all
274-
line=Line(width=trace[0]['edgewidth']))) # TODO: get all
268+
bar = go.Bar(
269+
orientation=orientation,
270+
x=x,
271+
y=y,
272+
xaxis='x{0}'.format(self.axis_ct),
273+
yaxis='y{0}'.format(self.axis_ct),
274+
opacity=trace[0]['alpha'], # TODO: get all alphas if array?
275+
marker=go.Marker(
276+
color=trace[0]['facecolor'], # TODO: get all
277+
line=go.Line(width=trace[0]['edgewidth']))) # TODO ditto
275278
if len(bar['x']) > 1:
276279
self.msg += " Heck yeah, I drew that bar chart\n"
277280
self.plotly_fig['data'] += bar,
@@ -282,7 +285,6 @@ def draw_bar(self, coll):
282285
warnings.warn('found box chart data with length <= 1, '
283286
'assuming data redundancy, not plotting.')
284287

285-
286288
def draw_marked_line(self, **props):
287289
"""Create a data dict for a line obj.
288290
@@ -328,32 +330,33 @@ def draw_marked_line(self, **props):
328330
self.msg += "... with just markers\n"
329331
mode = "markers"
330332
if props['linestyle']:
331-
line = Line(
333+
line = go.Line(
332334
opacity=props['linestyle']['alpha'],
333335
color=props['linestyle']['color'],
334336
width=props['linestyle']['linewidth'],
335337
dash=mpltools.convert_dash(props['linestyle']['dasharray'])
336338
)
337339
if props['markerstyle']:
338-
marker = Marker(
340+
marker = go.Marker(
339341
opacity=props['markerstyle']['alpha'],
340342
color=props['markerstyle']['facecolor'],
341343
symbol=mpltools.convert_symbol(props['markerstyle']['marker']),
342344
size=props['markerstyle']['markersize'],
343-
line=Line(
345+
line=go.Line(
344346
color=props['markerstyle']['edgecolor'],
345347
width=props['markerstyle']['edgewidth']
346348
)
347349
)
348350
if props['coordinates'] == 'data':
349-
marked_line = Scatter(mode=mode,
350-
name=props['label'],
351-
x=[xy_pair[0] for xy_pair in props['data']],
352-
y=[xy_pair[1] for xy_pair in props['data']],
353-
xaxis='x{0}'.format(self.axis_ct),
354-
yaxis='y{0}'.format(self.axis_ct),
355-
line=line,
356-
marker=marker)
351+
marked_line = go.Scatter(
352+
mode=mode,
353+
name=props['label'],
354+
x=[xy_pair[0] for xy_pair in props['data']],
355+
y=[xy_pair[1] for xy_pair in props['data']],
356+
xaxis='x{0}'.format(self.axis_ct),
357+
yaxis='y{0}'.format(self.axis_ct),
358+
line=line,
359+
marker=marker)
357360
self.plotly_fig['data'] += marked_line,
358361
self.msg += " Heck yeah, I drew that line\n"
359362
else:
@@ -459,7 +462,6 @@ def draw_path(self, **props):
459462
warnings.warn("I found a path object that I don't think is part "
460463
"of a bar chart. Ignoring.")
461464

462-
463465
def draw_text(self, **props):
464466
"""Create an annotation dict for a text obj.
465467
@@ -491,18 +493,19 @@ def draw_text(self, **props):
491493
"""
492494
self.msg += " Attempting to draw an mpl text object\n"
493495
if not mpltools.check_corners(props['mplobj'], self.mpl_fig):
494-
warnings.warn("Looks like the annotation(s) you are trying \n"
495-
"to draw lies/lay outside the given figure size.\n\n"
496-
"Therefore, the resulting Plotly figure may not be \n"
497-
"large enough to view the full text. To adjust \n"
498-
"the size of the figure, use the 'width' and \n"
499-
"'height' keys in the Layout object. Alternatively,\n"
500-
"use the Margin object to adjust the figure's margins.")
496+
warnings.warn(
497+
"Looks like the annotation(s) you are trying \n"
498+
"to draw lies/lay outside the given figure size.\n\n"
499+
"Therefore, the resulting Plotly figure may not be \n"
500+
"large enough to view the full text. To adjust \n"
501+
"the size of the figure, use the 'width' and \n"
502+
"'height' keys in the Layout object. Alternatively,\n"
503+
"use the Margin object to adjust the figure's margins.")
501504
align = props['mplobj']._multialignment
502505
if not align:
503-
align = props['style']['halign'] # mpl default
506+
align = props['style']['halign'] # mpl default
504507
if 'annotations' not in self.plotly_fig['layout']:
505-
self.plotly_fig['layout']['annotations'] = Annotations()
508+
self.plotly_fig['layout']['annotations'] = go.Annotations()
506509
if props['text_type'] == 'xlabel':
507510
self.msg += " Text object is an xlabel\n"
508511
self.draw_xlabel(**props)
@@ -519,8 +522,9 @@ def draw_text(self, **props):
519522
"coordinates\n"
520523
x_px, y_px = props['mplobj'].get_transform().transform(
521524
props['position'])
522-
x, y = mpltools.display_to_paper(x_px, y_px,
523-
self.plotly_fig['layout'])
525+
x, y = mpltools.display_to_paper(
526+
x_px, y_px, self.plotly_fig['layout']
527+
)
524528
xref = 'paper'
525529
yref = 'paper'
526530
xanchor = props['style']['halign'] # no difference here!
@@ -547,7 +551,7 @@ def draw_text(self, **props):
547551
yref = 'paper'
548552
xanchor = props['style']['halign'] # no difference here!
549553
yanchor = mpltools.convert_va(props['style']['valign'])
550-
annotation = Annotation(
554+
annotation = go.Annotation(
551555
text=props['text'],
552556
opacity=props['style']['alpha'],
553557
x=x,
@@ -558,7 +562,7 @@ def draw_text(self, **props):
558562
xanchor=xanchor,
559563
yanchor=yanchor,
560564
showarrow=False, # change this later?
561-
font=Font(
565+
font=go.Font(
562566
color=props['style']['color'],
563567
size=props['style']['fontsize']
564568
)
@@ -600,10 +604,11 @@ def draw_title(self, **props):
600604
'position'])
601605
x, y = mpltools.display_to_paper(x_px, y_px,
602606
self.plotly_fig['layout'])
603-
annotation = Annotation(
607+
annotation = go.Annotation(
604608
text=props['text'],
605-
font=Font(color=props['style']['color'],
606-
size=props['style']['fontsize']
609+
font=go.Font(
610+
color=props['style']['color'],
611+
size=props['style']['fontsize']
607612
),
608613
xref='paper',
609614
yref='paper',
@@ -618,8 +623,9 @@ def draw_title(self, **props):
618623
self.msg += " Only one subplot found, adding as a " \
619624
"plotly title\n"
620625
self.plotly_fig['layout']['title'] = props['text']
621-
titlefont = Font(size=props['style']['fontsize'],
622-
color=props['style']['color']
626+
titlefont = go.Font(
627+
size=props['style']['fontsize'],
628+
color=props['style']['color']
623629
)
624630
self.plotly_fig['layout']['titlefont'] = titlefont
625631

@@ -649,8 +655,9 @@ def draw_xlabel(self, **props):
649655
self.msg += " Adding xlabel\n"
650656
axis_key = 'xaxis{0}'.format(self.axis_ct)
651657
self.plotly_fig['layout'][axis_key]['title'] = props['text']
652-
titlefont = Font(size=props['style']['fontsize'],
653-
color=props['style']['color'])
658+
titlefont = go.Font(
659+
size=props['style']['fontsize'],
660+
color=props['style']['color'])
654661
self.plotly_fig['layout'][axis_key]['titlefont'] = titlefont
655662

656663
def draw_ylabel(self, **props):
@@ -679,8 +686,9 @@ def draw_ylabel(self, **props):
679686
self.msg += " Adding ylabel\n"
680687
axis_key = 'yaxis{0}'.format(self.axis_ct)
681688
self.plotly_fig['layout'][axis_key]['title'] = props['text']
682-
titlefont = Font(size=props['style']['fontsize'],
683-
color=props['style']['color'])
689+
titlefont = go.Font(
690+
size=props['style']['fontsize'],
691+
color=props['style']['color'])
684692
self.plotly_fig['layout'][axis_key]['titlefont'] = titlefont
685693

686694
def resize(self):

plotly/plotly/__init__.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
verifiable account (username/api-key pair) and a network connection.
88
99
"""
10-
from __future__ import absolute_import
11-
12-
from plotly.plotly.plotly import *
13-
14-
__all__ = ["sign_in", "update_plot_options", "get_plot_options",
15-
"get_credentials", "iplot", "plot", "iplot_mpl", "plot_mpl",
16-
"get_figure", "Stream", "image"]
10+
from . plotly import (
11+
sign_in, update_plot_options, get_plot_options, get_credentials, iplot,
12+
plot, iplot_mpl, plot_mpl, get_figure, Stream, image
13+
)

plotly/plotly/plotly.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@
3131
from plotly import version
3232

3333

34-
__all__ = ["sign_in", "update_plot_options", "get_plot_options",
35-
"get_credentials", "iplot", "plot", "iplot_mpl", "plot_mpl",
36-
"get_figure", "Stream", "image"]
34+
__all__ = None
3735

3836
_DEFAULT_PLOT_OPTIONS = dict(
3937
filename="plot from API",

0 commit comments

Comments
 (0)