Skip to content

Commit cf168ed

Browse files
authored
docstring refactoring in figure factory and various places (#1837)
1 parent 1ca5ba8 commit cf168ed

24 files changed

+976
-1116
lines changed

Diff for: packages/python/plotly/plotly/basedatatypes.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -1593,16 +1593,19 @@ def add_trace(self, trace, row=None, col=None, secondary_y=None):
15931593
15941594
Examples
15951595
--------
1596+
15961597
>>> from plotly import subplots
15971598
>>> import plotly.graph_objs as go
15981599
15991600
Add two Scatter traces to a figure
1601+
16001602
>>> fig = go.Figure()
16011603
>>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2]))
16021604
>>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2]))
16031605
16041606
16051607
Add two Scatter traces to vertically stacked subplots
1608+
16061609
>>> fig = subplots.make_subplots(rows=2)
16071610
>>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2]), row=1, col=1)
16081611
>>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2]), row=2, col=1)
@@ -1665,15 +1668,18 @@ def add_traces(self, data, rows=None, cols=None, secondary_ys=None):
16651668
16661669
Examples
16671670
--------
1671+
16681672
>>> from plotly import subplots
16691673
>>> import plotly.graph_objs as go
16701674
16711675
Add two Scatter traces to a figure
1676+
16721677
>>> fig = go.Figure()
16731678
>>> fig.add_traces([go.Scatter(x=[1,2,3], y=[2,1,2]),
16741679
... go.Scatter(x=[1,2,3], y=[2,1,2])])
16751680
16761681
Add two Scatter traces to vertically stacked subplots
1682+
16771683
>>> fig = subplots.make_subplots(rows=2)
16781684
>>> fig.add_traces([go.Scatter(x=[1,2,3], y=[2,1,2]),
16791685
... go.Scatter(x=[1,2,3], y=[2,1,2])],
@@ -1773,10 +1779,12 @@ def append_trace(self, trace, row, col):
17731779
17741780
Examples
17751781
--------
1782+
17761783
>>> from plotly import tools
17771784
>>> import plotly.graph_objs as go
1778-
# stack two subplots vertically
1785+
>>> # stack two subplots vertically
17791786
>>> fig = tools.make_subplots(rows=2)
1787+
17801788
This is the format of your plot grid:
17811789
[ (1,1) x1,y1 ]
17821790
[ (2,1) x2,y2 ]
@@ -2425,6 +2433,7 @@ def batch_update(self):
24252433
--------
24262434
For example, suppose we have a figure widget, `fig`, with a single
24272435
trace.
2436+
24282437
>>> import plotly.graph_objs as go
24292438
>>> fig = go.FigureWidget(data=[{'y': [3, 4, 2]}])
24302439
@@ -2593,6 +2602,7 @@ def batch_animate(self, duration=500, easing="cubic-in-out"):
25932602
25942603
2) Animate a change in the size and color of the trace's markers
25952604
over 2 seconds using the elastic-in-out easing method
2605+
25962606
>>> with fig.batch_update(duration=2000, easing='elastic-in-out'):
25972607
... fig.data[0].marker.color = 'green'
25982608
... fig.data[0].marker.size = 20
@@ -3055,6 +3065,7 @@ def _parent_path_str(self):
30553065
30563066
Examples
30573067
--------
3068+
30583069
>>> import plotly.graph_objs as go
30593070
>>> go.Layout()._parent_path_str
30603071
''
@@ -4582,6 +4593,7 @@ def on_hover(self, callback, append=False):
45824593
45834594
Examples
45844595
--------
4596+
45854597
>>> from plotly.callbacks import Points, InputDeviceState
45864598
>>> points, state = Points(), InputDeviceState()
45874599
@@ -4641,6 +4653,7 @@ def on_unhover(self, callback, append=False):
46414653
46424654
Examples
46434655
--------
4656+
46444657
>>> from plotly.callbacks import Points, InputDeviceState
46454658
>>> points, state = Points(), InputDeviceState()
46464659
@@ -4700,6 +4713,7 @@ def on_click(self, callback, append=False):
47004713
47014714
Examples
47024715
--------
4716+
47034717
>>> from plotly.callbacks import Points, InputDeviceState
47044718
>>> points, state = Points(), InputDeviceState()
47054719
@@ -4758,6 +4772,7 @@ def on_selection(self, callback, append=False):
47584772
47594773
Examples
47604774
--------
4775+
47614776
>>> from plotly.callbacks import Points
47624777
>>> points = Points()
47634778
@@ -4823,6 +4838,7 @@ def on_deselect(self, callback, append=False):
48234838
48244839
Examples
48254840
--------
4841+
48264842
>>> from plotly.callbacks import Points
48274843
>>> points = Points()
48284844

Diff for: packages/python/plotly/plotly/express/_doc.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
colref_type,
2828
colref_desc,
2929
"Values from this column or array_like are used to position marks along the x axis in cartesian coordinates.",
30-
"For horizontal `histogram`s, these values are used as inputs to `histfunc`.",
30+
"For horizontal histograms, these values are used as inputs to `histfunc`.",
3131
],
3232
y=[
3333
colref_type,
3434
colref_desc,
3535
"Values from this column or array_like are used to position marks along the y axis in cartesian coordinates.",
36-
"For vertical `histogram`s, these values are used as inputs to `histfunc`.",
36+
"For vertical histograms, these values are used as inputs to `histfunc`.",
3737
],
3838
z=[
3939
colref_type,
@@ -455,6 +455,7 @@ def make_docstring(fn):
455455
if param in docs
456456
else "(documentation missing from map)"
457457
)
458+
458459
param_type = docs[param][0]
459460
result += "%s: %s\n%s\n" % (param, param_type, param_desc)
460461
result += "\nReturns\n-------\n"

Diff for: packages/python/plotly/plotly/figure_factory/_2d_density.py

+29-31
Original file line numberDiff line numberDiff line change
@@ -51,49 +51,47 @@ def create_2d_density(
5151
:param (float) height: the height of the chart
5252
:param (float) width: the width of the chart
5353
54+
Examples
55+
--------
56+
5457
Example 1: Simple 2D Density Plot
55-
```
56-
import plotly.plotly as py
57-
from plotly.figure_factory create_2d_density
5858
59-
import numpy as np
59+
>>> from plotly.figure_factory create_2d_density
60+
61+
>>> import numpy as np
6062
61-
# Make data points
62-
t = np.linspace(-1,1.2,2000)
63-
x = (t**3)+(0.3*np.random.randn(2000))
64-
y = (t**6)+(0.3*np.random.randn(2000))
63+
>>> # Make data points
64+
>>> t = np.linspace(-1,1.2,2000)
65+
>>> x = (t**3)+(0.3*np.random.randn(2000))
66+
>>> y = (t**6)+(0.3*np.random.randn(2000))
6567
66-
# Create a figure
67-
fig = create_2D_density(x, y)
68+
>>> # Create a figure
69+
>>> fig = create_2D_density(x, y)
6870
69-
# Plot the data
70-
py.iplot(fig, filename='simple-2d-density')
71-
```
71+
>>> # Plot the data
72+
>>> fig.show()
7273
7374
Example 2: Using Parameters
74-
```
75-
import plotly.plotly as py
76-
from plotly.figure_factory create_2d_density
7775
78-
import numpy as np
76+
>>> from plotly.figure_factory create_2d_density
77+
78+
>>> import numpy as np
7979
80-
# Make data points
81-
t = np.linspace(-1,1.2,2000)
82-
x = (t**3)+(0.3*np.random.randn(2000))
83-
y = (t**6)+(0.3*np.random.randn(2000))
80+
>>> # Make data points
81+
>>> t = np.linspace(-1,1.2,2000)
82+
>>> x = (t**3)+(0.3*np.random.randn(2000))
83+
>>> y = (t**6)+(0.3*np.random.randn(2000))
8484
85-
# Create custom colorscale
86-
colorscale = ['#7A4579', '#D56073', 'rgb(236,158,105)',
87-
(1, 1, 0.2), (0.98,0.98,0.98)]
85+
>>> # Create custom colorscale
86+
>>> colorscale = ['#7A4579', '#D56073', 'rgb(236,158,105)',
87+
... (1, 1, 0.2), (0.98,0.98,0.98)]
8888
89-
# Create a figure
90-
fig = create_2D_density(
91-
x, y, colorscale=colorscale,
92-
hist_color='rgb(255, 237, 222)', point_size=3)
89+
>>> # Create a figure
90+
>>> fig = create_2D_density(x, y, colorscale=colorscale,
91+
... hist_color='rgb(255, 237, 222)', point_size=3)
9392
94-
# Plot the data
95-
py.iplot(fig, filename='use-parameters')
96-
```
93+
>>> # Plot the data
94+
>>> fig.show()
9795
"""
9896

9997
# validate x and y are filled with numbers only

Diff for: packages/python/plotly/plotly/figure_factory/_annotated_heatmap.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,16 @@ def create_annotated_heatmap(
8484
call help(plotly.graph_objs.Heatmap)
8585
8686
Example 1: Simple annotated heatmap with default configuration
87-
```
88-
import plotly.plotly as py
89-
import plotly.figure_factory as FF
9087
91-
z = [[0.300000, 0.00000, 0.65, 0.300000],
92-
[1, 0.100005, 0.45, 0.4300],
93-
[0.300000, 0.00000, 0.65, 0.300000],
94-
[1, 0.100005, 0.45, 0.00000]]
88+
>>> import plotly.figure_factory as ff
89+
90+
>>> z = [[0.300000, 0.00000, 0.65, 0.300000],
91+
... [1, 0.100005, 0.45, 0.4300],
92+
... [0.300000, 0.00000, 0.65, 0.300000],
93+
... [1, 0.100005, 0.45, 0.00000]]
9594
96-
figure = FF.create_annotated_heatmap(z)
97-
py.iplot(figure)
95+
>>> fig = ff.create_annotated_heatmap(z)
96+
>>> fig.show()
9897
```
9998
"""
10099

Diff for: packages/python/plotly/plotly/figure_factory/_bullet.py

+30-39
Original file line numberDiff line numberDiff line change
@@ -238,49 +238,40 @@ def create_bullet(
238238
for more information on valid params.
239239
240240
Example 1: Use a Dictionary
241-
```
242-
import plotly
243-
import plotly.plotly as py
244-
import plotly.figure_factory as ff
245-
246-
data = [
247-
{"label": "Revenue", "sublabel": "US$, in thousands",
248-
"range": [150, 225, 300], "performance": [220,270], "point": [250]},
249-
{"label": "Profit", "sublabel": "%", "range": [20, 25, 30],
250-
"performance": [21, 23], "point": [26]},
251-
{"label": "Order Size", "sublabel":"US$, average","range": [350, 500, 600],
252-
"performance": [100,320],"point": [550]},
253-
{"label": "New Customers", "sublabel": "count", "range": [1400, 2000, 2500],
254-
"performance": [1000, 1650],"point": [2100]},
255-
{"label": "Satisfaction", "sublabel": "out of 5","range": [3.5, 4.25, 5],
256-
"performance": [3.2, 4.7], "point": [4.4]}
257-
]
258-
259-
fig = ff.create_bullet(
260-
data, titles='label', subtitles='sublabel', markers='point',
261-
measures='performance', ranges='range', orientation='h',
262-
title='my simple bullet chart'
263-
)
264-
py.iplot(fig)
265-
```
241+
242+
>>> import plotly.figure_factory as ff
243+
244+
>>> data = [
245+
... {"label": "revenue", "sublabel": "us$, in thousands",
246+
... "range": [150, 225, 300], "performance": [220,270], "point": [250]},
247+
... {"label": "Profit", "sublabel": "%", "range": [20, 25, 30],
248+
... "performance": [21, 23], "point": [26]},
249+
... {"label": "Order Size", "sublabel":"US$, average","range": [350, 500, 600],
250+
... "performance": [100,320],"point": [550]},
251+
... {"label": "New Customers", "sublabel": "count", "range": [1400, 2000, 2500],
252+
... "performance": [1000, 1650],"point": [2100]},
253+
... {"label": "Satisfaction", "sublabel": "out of 5","range": [3.5, 4.25, 5],
254+
... "performance": [3.2, 4.7], "point": [4.4]}
255+
... ]
256+
257+
>>> fig = ff.create_bullet(
258+
... data, titles='label', subtitles='sublabel', markers='point',
259+
... measures='performance', ranges='range', orientation='h',
260+
... title='my simple bullet chart'
261+
... )
262+
>>> fig.show()
266263
267264
Example 2: Use a DataFrame with Custom Colors
268-
```
269-
import plotly.plotly as py
270-
import plotly.figure_factory as ff
271-
272-
import pandas as pd
273265
274-
data = pd.read_json('https://cdn.rawgit.com/plotly/datasets/master/BulletData.json')
266+
>>> import plotly.figure_factory as ff
267+
>>> import pandas as pd
268+
>>> data = pd.read_json('https://cdn.rawgit.com/plotly/datasets/master/BulletData.json')
275269
276-
fig = ff.create_bullet(
277-
data, titles='title', markers='markers', measures='measures',
278-
orientation='v', measure_colors=['rgb(14, 52, 75)', 'rgb(31, 141, 127)'],
279-
scatter_options={'marker': {'symbol': 'circle'}}, width=700
280-
281-
)
282-
py.iplot(fig)
283-
```
270+
>>> fig = ff.create_bullet(
271+
... data, titles='title', markers='markers', measures='measures',
272+
... orientation='v', measure_colors=['rgb(14, 52, 75)', 'rgb(31, 141, 127)'],
273+
... scatter_options={'marker': {'symbol': 'circle'}}, width=700)
274+
>>> fig.show()
284275
"""
285276
# validate df
286277
if not pd:

0 commit comments

Comments
 (0)