diff --git a/.circleci/config.yml b/.circleci/config.yml index 25583c16e04..4e0788a69e8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -325,6 +325,7 @@ jobs: command: | . /home/circleci/miniconda/etc/profile.d/conda.sh conda activate circle_optional + pytest --doctest-modules --ignore packages/python/plotly/plotly/tests --ignore packages/python/plotly/plotly/matplotlylib/mplexporter/tests packages/python/plotly/plotly pytest --disable-warnings packages/python/plotly/plotly/tests/test_core pytest packages/python/plotly/plotly/tests/test_orca diff --git a/.circleci/create_conda_optional_env.sh b/.circleci/create_conda_optional_env.sh index 3cbbc63966a..ebd907688a5 100755 --- a/.circleci/create_conda_optional_env.sh +++ b/.circleci/create_conda_optional_env.sh @@ -16,7 +16,7 @@ if [ ! -d $HOME/miniconda/envs/circle_optional ]; then # Create environment # PYTHON_VERSION=3.6 $HOME/miniconda/bin/conda create -n circle_optional --yes python=$PYTHON_VERSION \ -requests nbformat six retrying psutil pandas decorator pytest mock nose poppler xarray scikit-image ipython +requests nbformat six retrying psutil pandas decorator pytest mock nose poppler xarray scikit-image ipython jupyter ipykernel ipywidgets # Install orca into environment $HOME/miniconda/bin/conda install --yes -n circle_optional -c plotly plotly-orca diff --git a/packages/python/plotly/plotly/basedatatypes.py b/packages/python/plotly/plotly/basedatatypes.py index 22469d43034..cd551fc31c7 100644 --- a/packages/python/plotly/plotly/basedatatypes.py +++ b/packages/python/plotly/plotly/basedatatypes.py @@ -458,8 +458,9 @@ def update(self, dict1=None, overwrite=False, **kwargs): -------- >>> import plotly.graph_objs as go >>> fig = go.Figure(data=[{'y': [1, 2, 3]}]) - >>> fig.update(data=[{'y': [4, 5, 6]}]) - >>> fig.to_plotly_json() + >>> fig.update(data=[{'y': [4, 5, 6]}]) # doctest: +ELLIPSIS + Figure(...) + >>> fig.to_plotly_json() # doctest: +SKIP {'data': [{'type': 'scatter', 'uid': 'e86a7c7a-346a-11e8-8aa8-a0999b0c017b', 'y': array([4, 5, 6], dtype=int32)}], @@ -468,8 +469,9 @@ def update(self, dict1=None, overwrite=False, **kwargs): >>> fig = go.Figure(layout={'xaxis': ... {'color': 'green', ... 'range': [0, 1]}}) - >>> fig.update({'layout': {'xaxis': {'color': 'pink'}}}) - >>> fig.to_plotly_json() + >>> fig.update({'layout': {'xaxis': {'color': 'pink'}}}) # doctest: +ELLIPSIS + Figure(...) + >>> fig.to_plotly_json() # doctest: +SKIP {'data': [], 'layout': {'xaxis': {'color': 'pink', @@ -1128,6 +1130,8 @@ def plotly_restyle(self, restyle_data, trace_indexes=None, **kwargs): example, the following command would be used to update the 'x' property of the first trace to the list [1, 2, 3] + >>> import plotly.graph_objects as go + >>> fig = go.Figure(go.Scatter(x=[2, 4, 6])) >>> fig.plotly_restyle({'x': [[1, 2, 3]]}, 0) trace_indexes : int or list of int @@ -1586,15 +1590,19 @@ def add_trace(self, trace, row=None, col=None, secondary_y=None): Add two Scatter traces to a figure >>> fig = go.Figure() - >>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2])) - >>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2])) + >>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2])) # doctest: +ELLIPSIS + Figure(...) + >>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2])) # doctest: +ELLIPSIS + Figure(...) Add two Scatter traces to vertically stacked subplots >>> fig = subplots.make_subplots(rows=2) - >>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2]), row=1, col=1) - >>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2]), row=2, col=1) + >>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2]), row=1, col=1) # doctest: +ELLIPSIS + Figure(...) + >>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2]), row=2, col=1) # doctest: +ELLIPSIS + Figure(...) """ # Make sure we have both row and col or neither if row is not None and col is None: @@ -1662,14 +1670,16 @@ def add_traces(self, data, rows=None, cols=None, secondary_ys=None): >>> fig = go.Figure() >>> fig.add_traces([go.Scatter(x=[1,2,3], y=[2,1,2]), - ... go.Scatter(x=[1,2,3], y=[2,1,2])]) + ... go.Scatter(x=[1,2,3], y=[2,1,2])]) # doctest: +ELLIPSIS + Figure(...) Add two Scatter traces to vertically stacked subplots >>> fig = subplots.make_subplots(rows=2) >>> fig.add_traces([go.Scatter(x=[1,2,3], y=[2,1,2]), ... go.Scatter(x=[1,2,3], y=[2,1,2])], - ... rows=[1, 2], cols=[1, 1]) + ... rows=[1, 2], cols=[1, 1]) # doctest: +ELLIPSIS + Figure(...) """ # Validate traces @@ -2152,11 +2162,12 @@ def _build_dispatch_plan(key_path_strs): Examples -------- + >>> key_path_strs = ['xaxis.rangeselector.font.color', ... 'xaxis.rangeselector.bgcolor'] - >>> BaseFigure._build_dispatch_plan(key_path_strs) - {(): {('xaxis',), + >>> BaseFigure._build_dispatch_plan(key_path_strs) # doctest: +SKIP + {(): {'xaxis', ('xaxis', 'rangeselector'), ('xaxis', 'rangeselector', 'bgcolor'), ('xaxis', 'rangeselector', 'font'), @@ -2589,7 +2600,7 @@ def batch_animate(self, duration=500, easing="cubic-in-out"): 2) Animate a change in the size and color of the trace's markers over 2 seconds using the elastic-in-out easing method - >>> with fig.batch_update(duration=2000, easing='elastic-in-out'): + >>> with fig.batch_animate(duration=2000, easing='elastic-in-out'): ... fig.data[0].marker.color = 'green' ... fig.data[0].marker.size = 20 """ @@ -4088,6 +4099,8 @@ def on_change(self, callback, *args, **kwargs): Register callback that prints out the range extents of the xaxis and yaxis whenever either either of them changes. + >>> import plotly.graph_objects as go + >>> fig = go.Figure(go.Scatter(x=[1, 2], y=[1, 0])) >>> fig.layout.on_change( ... lambda obj, xrange, yrange: print("%s-%s" % (xrange, yrange)), ... ('xaxis', 'range'), ('yaxis', 'range')) @@ -4572,6 +4585,7 @@ def on_hover(self, callback, append=False): Examples -------- + >>> import plotly.graph_objects as go >>> from plotly.callbacks import Points, InputDeviceState >>> points, state = Points(), InputDeviceState() @@ -4579,6 +4593,7 @@ def on_hover(self, callback, append=False): ... inds = points.point_inds ... # Do something + >>> trace = go.Scatter(x=[1, 2], y=[3, 0]) >>> trace.on_hover(hover_fn) Note: The creation of the `points` and `state` objects is optional, @@ -4632,6 +4647,7 @@ def on_unhover(self, callback, append=False): Examples -------- + >>> import plotly.graph_objects as go >>> from plotly.callbacks import Points, InputDeviceState >>> points, state = Points(), InputDeviceState() @@ -4639,6 +4655,7 @@ def on_unhover(self, callback, append=False): ... inds = points.point_inds ... # Do something + >>> trace = go.Scatter(x=[1, 2], y=[3, 0]) >>> trace.on_unhover(unhover_fn) Note: The creation of the `points` and `state` objects is optional, @@ -4692,6 +4709,7 @@ def on_click(self, callback, append=False): Examples -------- + >>> import plotly.graph_objects as go >>> from plotly.callbacks import Points, InputDeviceState >>> points, state = Points(), InputDeviceState() @@ -4699,6 +4717,7 @@ def on_click(self, callback, append=False): ... inds = points.point_inds ... # Do something + >>> trace = go.Scatter(x=[1, 2], y=[3, 0]) >>> trace.on_click(click_fn) Note: The creation of the `points` and `state` objects is optional, @@ -4751,6 +4770,7 @@ def on_selection(self, callback, append=False): Examples -------- + >>> import plotly.graph_objects as go >>> from plotly.callbacks import Points >>> points = Points() @@ -4758,6 +4778,7 @@ def on_selection(self, callback, append=False): ... inds = points.point_inds ... # Do something + >>> trace = go.Scatter(x=[1, 2], y=[3, 0]) >>> trace.on_selection(selection_fn) Note: The creation of the `points` object is optional, @@ -4817,6 +4838,7 @@ def on_deselect(self, callback, append=False): Examples -------- + >>> import plotly.graph_objects as go >>> from plotly.callbacks import Points >>> points = Points() @@ -4824,6 +4846,7 @@ def on_deselect(self, callback, append=False): ... inds = points.point_inds ... # Do something + >>> trace = go.Scatter(x=[1, 2], y=[3, 0]) >>> trace.on_deselect(deselect_fn) Note: The creation of the `points` object is optional, diff --git a/packages/python/plotly/plotly/conftest.py b/packages/python/plotly/plotly/conftest.py new file mode 100644 index 00000000000..3e7bed965e6 --- /dev/null +++ b/packages/python/plotly/plotly/conftest.py @@ -0,0 +1,25 @@ +import pytest +import os + + +def pytest_ignore_collect(path): + # Ignored files, most of them are raising a chart studio error + ignored_paths = [ + "exploding_module.py", + "chunked_requests.py", + "v2.py", + "v1.py", + "presentation_objs.py", + "widgets.py", + "dashboard_objs.py", + "grid_objs.py", + "config.py", + "presentation_objs.py", + "session.py", + ] + if ( + os.path.basename(str(path)) in ignored_paths + or "plotly/plotly/plotly/__init__.py" in str(path) + or "plotly/api/utils.py" in str(path) + ): + return True diff --git a/packages/python/plotly/plotly/figure_factory/_2d_density.py b/packages/python/plotly/plotly/figure_factory/_2d_density.py index 5a96d4b3718..e6d7d7874d2 100644 --- a/packages/python/plotly/plotly/figure_factory/_2d_density.py +++ b/packages/python/plotly/plotly/figure_factory/_2d_density.py @@ -32,7 +32,8 @@ def create_2d_density( width=600, ): """ - Returns figure for a 2D density plot + **deprecated**, use instead + :func:`plotly.express.density_heatmap`. :param (list|array) x: x-axis data for plot generation :param (list|array) y: y-axis data for plot generation @@ -56,8 +57,7 @@ def create_2d_density( Example 1: Simple 2D Density Plot - >>> from plotly.figure_factory create_2d_density - + >>> from plotly.figure_factory import create_2d_density >>> import numpy as np >>> # Make data points @@ -66,14 +66,14 @@ def create_2d_density( >>> y = (t**6)+(0.3*np.random.randn(2000)) >>> # Create a figure - >>> fig = create_2D_density(x, y) + >>> fig = create_2d_density(x, y) >>> # Plot the data >>> fig.show() Example 2: Using Parameters - >>> from plotly.figure_factory create_2d_density + >>> from plotly.figure_factory import create_2d_density >>> import numpy as np @@ -87,7 +87,7 @@ def create_2d_density( ... (1, 1, 0.2), (0.98,0.98,0.98)] >>> # Create a figure - >>> fig = create_2D_density(x, y, colorscale=colorscale, + >>> fig = create_2d_density(x, y, colorscale=colorscale, ... hist_color='rgb(255, 237, 222)', point_size=3) >>> # Plot the data diff --git a/packages/python/plotly/plotly/figure_factory/_annotated_heatmap.py b/packages/python/plotly/plotly/figure_factory/_annotated_heatmap.py index c3b1e2fa989..9b5bf0a0b17 100644 --- a/packages/python/plotly/plotly/figure_factory/_annotated_heatmap.py +++ b/packages/python/plotly/plotly/figure_factory/_annotated_heatmap.py @@ -59,7 +59,7 @@ def create_annotated_heatmap( **kwargs ): """ - BETA function that creates annotated heatmaps + Function that creates annotated heatmaps This function adds annotations to each cell of the heatmap. @@ -94,7 +94,6 @@ def create_annotated_heatmap( >>> fig = ff.create_annotated_heatmap(z) >>> fig.show() - ``` """ # Avoiding mutables in the call signature diff --git a/packages/python/plotly/plotly/figure_factory/_bullet.py b/packages/python/plotly/plotly/figure_factory/_bullet.py index 111e713a3a4..7d5a23ae2e4 100644 --- a/packages/python/plotly/plotly/figure_factory/_bullet.py +++ b/packages/python/plotly/plotly/figure_factory/_bullet.py @@ -198,7 +198,8 @@ def create_bullet( **layout_options ): """ - Returns figure for bullet chart. + **deprecated**, use instead the plotly.graph_objects trace + :class:`plotly.graph_objects.Indicator`. :param (pd.DataFrame | list | tuple) data: either a list/tuple of dictionaries or a pandas DataFrame. diff --git a/packages/python/plotly/plotly/figure_factory/_candlestick.py b/packages/python/plotly/plotly/figure_factory/_candlestick.py index db4cc507355..2ab76122530 100644 --- a/packages/python/plotly/plotly/figure_factory/_candlestick.py +++ b/packages/python/plotly/plotly/figure_factory/_candlestick.py @@ -99,7 +99,8 @@ def make_decreasing_candle(open, high, low, close, dates, **kwargs): def create_candlestick(open, high, low, close, dates=None, direction="both", **kwargs): """ - BETA function that creates a candlestick chart + **deprecated**, use instead the plotly.graph_objects trace + :class:`plotly.graph_objects.Candlestick` :param (list) open: opening values :param (list) high: high values @@ -125,51 +126,32 @@ def create_candlestick(open, high, low, close, dates=None, direction="both", **k >>> from plotly.figure_factory import create_candlestick >>> from datetime import datetime + >>> import pandas as pd - >>> import pandas.io.data as web - - >>> df = web.DataReader("aapl", 'yahoo', datetime(2007, 10, 1), datetime(2009, 4, 1)) - >>> fig = create_candlestick(df.Open, df.High, df.Low, df.Close, dates=df.index) + >>> df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv') + >>> fig = create_candlestick(df['AAPL.Open'], df['AAPL.High'], df['AAPL.Low'], df['AAPL.Close'], + ... dates=df.index) >>> fig.show() - Example 2: Add text and annotations to the candlestick chart - - >>> fig = create_candlestick(df.Open, df.High, df.Low, df.Close, dates=df.index) - >>> # Update the fig - all options here: https://plot.ly/python/reference/#Layout - >>> fig['layout'].update({ - 'title': 'The Great Recession', - 'yaxis': {'title': 'AAPL Stock'}, - 'shapes': [{ - 'x0': '2007-12-01', 'x1': '2007-12-01', - 'y0': 0, 'y1': 1, 'xref': 'x', 'yref': 'paper', - 'line': {'color': 'rgb(30,30,30)', 'width': 1} - }], - 'annotations': [{ - 'x': '2007-12-01', 'y': 0.05, 'xref': 'x', 'yref': 'paper', - 'showarrow': False, 'xanchor': 'left', - 'text': 'Official start of the recession' - }] - }) - >>> fig.show() + Example 2: Customize the candlestick colors - Example 3: Customize the candlestick colors - >>> from plotly.figure_factory import create_candlestick >>> from plotly.graph_objs import Line, Marker >>> from datetime import datetime - >>> import pandas.io.data as web - - >>> df = web.DataReader("aapl", 'yahoo', datetime(2008, 1, 1), datetime(2009, 4, 1)) + >>> import pandas as pd + >>> df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv') >>> # Make increasing candlesticks and customize their color and name - >>> fig_increasing = create_candlestick(df.Open, df.High, df.Low, df.Close, dates=df.index, + >>> fig_increasing = create_candlestick(df['AAPL.Open'], df['AAPL.High'], df['AAPL.Low'], df['AAPL.Close'], + ... dates=df.index, ... direction='increasing', name='AAPL', ... marker=Marker(color='rgb(150, 200, 250)'), ... line=Line(color='rgb(150, 200, 250)')) >>> # Make decreasing candlesticks and customize their color and name - >>> fig_decreasing = create_candlestick(df.Open, df.High, df.Low, df.Close, dates=df.index, + >>> fig_decreasing = create_candlestick(df['AAPL.Open'], df['AAPL.High'], df['AAPL.Low'], df['AAPL.Close'], + ... dates=df.index, ... direction='decreasing', ... marker=Marker(color='rgb(128, 128, 128)'), ... line=Line(color='rgb(128, 128, 128)')) @@ -178,11 +160,11 @@ def create_candlestick(open, high, low, close, dates=None, direction="both", **k >>> fig = fig_increasing >>> # Add decreasing data with .extend() - >>> fig['data'].extend(fig_decreasing['data']) + >>> fig.add_trace(fig_decreasing['data']) # doctest: +SKIP >>> fig.show() - Example 4: Candlestick chart with datetime objects - + Example 3: Candlestick chart with datetime objects + >>> from plotly.figure_factory import create_candlestick >>> from datetime import datetime @@ -202,7 +184,6 @@ def create_candlestick(open, high, low, close, dates=None, direction="both", **k >>> fig = create_candlestick(open_data, high_data, ... low_data, close_data, dates=dates) >>> fig.show() - """ if dates is not None: utils.validate_equal_length(open, high, low, close, dates) diff --git a/packages/python/plotly/plotly/figure_factory/_dendrogram.py b/packages/python/plotly/plotly/figure_factory/_dendrogram.py index 14ae27bccce..380487e9a82 100644 --- a/packages/python/plotly/plotly/figure_factory/_dendrogram.py +++ b/packages/python/plotly/plotly/figure_factory/_dendrogram.py @@ -25,7 +25,9 @@ def create_dendrogram( color_threshold=None, ): """ - BETA function that returns a dendrogram Plotly figure object. + Function that returns a dendrogram Plotly figure object. + + See also https://dash.plot.ly/dash-bio/clustergram. :param (ndarray) X: Matrix of observations as array of arrays :param (str) orientation: 'top', 'right', 'bottom', or 'left' @@ -58,7 +60,7 @@ def create_dendrogram( >>> X = np.random.rand(5,5) >>> names = ['Jack', 'Oxana', 'John', 'Chelsea', 'Mark'] >>> dendro = create_dendrogram(X, orientation='right', labels=names) - >>> dendro['layout'].update({'width':700, 'height':500}) + >>> dendro.update_layout({'width':700, 'height':500}) # doctest: +SKIP >>> dendro.show() Example 3: Dendrogram with Pandas diff --git a/packages/python/plotly/plotly/figure_factory/_distplot.py b/packages/python/plotly/plotly/figure_factory/_distplot.py index 2808931abe9..52cd08b69ab 100644 --- a/packages/python/plotly/plotly/figure_factory/_distplot.py +++ b/packages/python/plotly/plotly/figure_factory/_distplot.py @@ -62,7 +62,16 @@ def create_distplot( show_rug=True, ): """ - BETA function that creates a distplot similar to seaborn.distplot + Function that creates a distplot similar to seaborn.distplot; + **this function is deprecated**, use instead :mod:`plotly.express` + functions, for example + + >>> import plotly.express as px + >>> tips = px.data.tips() + >>> fig = px.histogram(tips, x="total_bill", y="tip", color="sex", marginal="rug", + ... hover_data=tips.columns) + >>> fig.show() + The distplot can be composed of all or any combination of the following 3 components: (1) histogram, (2) curve: (a) kernel density estimation @@ -130,7 +139,7 @@ def create_distplot( ... hist_data, group_labels, rug_text=rug_text_all, bin_size=.2) >>> # Add title - >>> fig['layout'].update(title='Dist Plot') + >>> fig.update_layout(title='Dist Plot') # doctest: +SKIP >>> fig.show() @@ -159,7 +168,7 @@ def create_distplot( >>> import pandas as pd >>> df = pd.DataFrame({'2012': np.random.randn(200), - >>> '2013': np.random.randn(200)+1}) + ... '2013': np.random.randn(200)+1}) >>> fig = create_distplot([df[c] for c in df.columns], df.columns) >>> fig.show() """ diff --git a/packages/python/plotly/plotly/figure_factory/_facet_grid.py b/packages/python/plotly/plotly/figure_factory/_facet_grid.py index 95e0f70edec..9fc47879c22 100644 --- a/packages/python/plotly/plotly/figure_factory/_facet_grid.py +++ b/packages/python/plotly/plotly/figure_factory/_facet_grid.py @@ -673,7 +673,18 @@ def create_facet_grid( **kwargs ): """ - Returns figure for facet grid. + Returns figure for facet grid; **this function is deprecated**, since + plotly.express functions should be used instead, for example + + >>> import plotly.express as px + >>> tips = px.data.tips() + >>> fig = px.scatter(tips, + ... x='total_bill', + ... y='tip', + ... facet_row='sex', + ... facet_col='smoker', + ... color='size') + :param (pd.DataFrame) df: the dataframe of columns for the facet grid. :param (str) x: the name of the dataframe column for the x axis data. @@ -754,7 +765,8 @@ def create_facet_grid( >>> import plotly.figure_factory as ff >>> import pandas as pd - >>> mpg = pd.read_table('https://raw.githubusercontent.com/plotly/datasets/master/mpg_2017.txt') + >>> mtcars = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/mtcars.csv') + >>> mtcars.cyl = mtcars.cyl.astype(str) >>> fig = ff.create_facet_grid( ... mtcars, ... x='mpg', @@ -765,49 +777,7 @@ def create_facet_grid( ... ) >>> fig.show() - Example 4: Sequential Coloring - - >>> import plotly.figure_factory as ff - >>> import pandas as pd - >>> tips = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/tips.csv') - - >>> fig = ff.create_facet_grid( - >>> tips, - ... x='total_bill', - ... y='tip', - ... facet_row='sex', - ... facet_col='smoker', - ... color_name='size', - ... colormap='Viridis', - ... ) - >>> fig.show() - - Example 5: Custom labels - - >>> import plotly.figure_factory as ff - >>> import pandas as pd - >>> mtcars = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/mtcars.csv') - >>> fig = ff.create_facet_grid( - ... mtcars, - ... x='wt', - ... y='mpg', - ... facet_col='cyl', - ... facet_col_labels={4: "$\\alpha$", 6: '$\\beta$', 8: '$\sqrt[y]{x}$'}, - ... ) - >>> fig.show() - Example 6: Other Trace Type - - >>> import plotly.figure_factory as ff - >>> import pandas as pd - >>> mtcars = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/mtcars.csv') - >>> fig = ff.create_facet_grid( - ... mtcars, - ... x='wt', - ... facet_col='cyl', - ... trace_type='histogram', - ... ) - >>> fig.show() """ if not pd: raise ImportError("'pandas' must be installed for this figure_factory.") diff --git a/packages/python/plotly/plotly/figure_factory/_gantt.py b/packages/python/plotly/plotly/figure_factory/_gantt.py index f4ec5f58281..3d3f8f5cdd5 100644 --- a/packages/python/plotly/plotly/figure_factory/_gantt.py +++ b/packages/python/plotly/plotly/figure_factory/_gantt.py @@ -820,6 +820,7 @@ def create_gantt( ): """ Returns figure for a gantt chart + :param (array|list) df: input data for gantt chart. Must be either a a dataframe or a list. If dataframe, the columns must include 'Task', 'Start' and 'Finish'. Other columns can be included and diff --git a/packages/python/plotly/plotly/figure_factory/_ohlc.py b/packages/python/plotly/plotly/figure_factory/_ohlc.py index 3122bb0a6c5..49ca1aa196a 100644 --- a/packages/python/plotly/plotly/figure_factory/_ohlc.py +++ b/packages/python/plotly/plotly/figure_factory/_ohlc.py @@ -134,7 +134,8 @@ def make_decreasing_ohlc(open, high, low, close, dates, **kwargs): def create_ohlc(open, high, low, close, dates=None, direction="both", **kwargs): """ - BETA function that creates an ohlc chart + **deprecated**, use instead the plotly.graph_objects trace + :class:`plotly.graph_objects.Ohlc` :param (list) open: opening values :param (list) high: high values @@ -161,91 +162,9 @@ def create_ohlc(open, high, low, close, dates=None, direction="both", **kwargs): >>> from plotly.figure_factory import create_ohlc >>> from datetime import datetime - >>> import pandas.io.data as web - - >>> df = web.DataReader("aapl", 'yahoo', datetime(2008, 8, 15), - ... datetime(2008, 10, 15)) - >>> fig = create_ohlc(df.Open, df.High, df.Low, df.Close, dates=df.index) - >>> fig.show() - - Example 2: Add text and annotations to the OHLC chart - - >>> from plotly.figure_factory import create_ohlc - >>> from datetime import datetime - - >>> import pandas.io.data as web - - >>> df = web.datareader("aapl", 'yahoo', datetime(2008, 8, 15), - ... datetime(2008, 10, 15)) - >>> fig = create_ohlc(df.open, df.high, df.low, df.close, dates=df.index) - - >>> # update the fig - options here: https://plot.ly/python/reference/#layout - >>> fig['layout'].update({ - ... 'title': 'the great recession', - ... 'yaxis': {'title': 'aapl stock'}, - ... 'shapes': [{ - ... 'x0': '2008-09-15', 'x1': '2008-09-15', 'type': 'line', - ... 'y0': 0, 'y1': 1, 'xref': 'x', 'yref': 'paper', - ... 'line': {'color': 'rgb(40,40,40)', 'width': 0.5} - ... }], - ... 'annotations': [{ - ... 'text': "the fall of lehman brothers", - ... 'x': '2008-09-15', 'y': 1.02, - ... 'xref': 'x', 'yref': 'paper', - ... 'showarrow': false, 'xanchor': 'left' - ... }] - ... }) - >>> fig.show() - - Example 3: Customize the OHLC colors - - >>> from plotly.figure_factory import create_ohlc - >>> from plotly.graph_objs import Line, Marker - >>> from datetime import datetime - - >>> import pandas.io.data as web - - >>> df = web.DataReader("aapl", 'yahoo', datetime(2008, 1, 1), - ... datetime(2009, 4, 1)) - - >>> # Make increasing ohlc sticks and customize their color and name - >>> fig_increasing = create_ohlc(df.Open, df.High, df.Low, df.Close, - ... dates=df.index, direction='increasing', - ... name='AAPL', - ... line=Line(color='rgb(150, 200, 250)')) - - >>> # Make decreasing ohlc sticks and customize their color and name - >>> fig_decreasing = create_ohlc(df.Open, df.High, df.Low, df.Close, - ... dates=df.index, direction='decreasing', - ... line=Line(color='rgb(128, 128, 128)')) - - >>> # Initialize the figure - >>> fig = fig_increasing - - >>> # Add decreasing data with .extend() - >>> fig['data'].extend(fig_decreasing['data']) - >>> fig.show() - - - Example 4: OHLC chart with datetime objects - - >>> from plotly.figure_factory import create_ohlc - - >>> from datetime import datetime - - >>> # Add data - >>> open_data = [33.0, 33.3, 33.5, 33.0, 34.1] - >>> high_data = [33.1, 33.3, 33.6, 33.2, 34.8] - >>> low_data = [32.7, 32.7, 32.8, 32.6, 32.8] - >>> close_data = [33.0, 32.9, 33.3, 33.1, 33.1] - >>> dates = [datetime(year=2013, month=10, day=10), - ... datetime(year=2013, month=11, day=10), - ... datetime(year=2013, month=12, day=10), - ... datetime(year=2014, month=1, day=10), - ... datetime(year=2014, month=2, day=10)] - - >>> # Create ohlc - >>> fig = create_ohlc(open_data, high_data, low_data, close_data, dates=dates) + >>> import pandas as pd + >>> df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv') + >>> fig = create_ohlc(df['AAPL.Open'], df['AAPL.High'], df['AAPL.Low'], df['AAPL.Close'], dates=df.index) >>> fig.show() """ if dates is not None: diff --git a/packages/python/plotly/plotly/figure_factory/_quiver.py b/packages/python/plotly/plotly/figure_factory/_quiver.py index e9503515ea1..f40df33d451 100644 --- a/packages/python/plotly/plotly/figure_factory/_quiver.py +++ b/packages/python/plotly/plotly/figure_factory/_quiver.py @@ -75,7 +75,7 @@ def create_quiver( ... name='Wind Velocity', line=dict(width=1)) >>> # Add title to layout - >>> fig['layout'].update(title='Quiver Plot') + >>> fig.update_layout(title='Quiver Plot') # doctest: +SKIP >>> fig.show() diff --git a/packages/python/plotly/plotly/figure_factory/_scatterplot.py b/packages/python/plotly/plotly/figure_factory/_scatterplot.py index 9d606c1d7ac..65164db0319 100644 --- a/packages/python/plotly/plotly/figure_factory/_scatterplot.py +++ b/packages/python/plotly/plotly/figure_factory/_scatterplot.py @@ -854,7 +854,10 @@ def create_scatterplotmatrix( **kwargs ): """ - Returns data for a scatterplot matrix. + Returns data for a scatterplot matrix; + **deprecated**, + use instead the plotly.graph_objects trace + :class:`plotly.graph_objects.Splom`. :param (array) df: array of the data with column headers :param (str) index: name of the index column in data array diff --git a/packages/python/plotly/plotly/figure_factory/_streamline.py b/packages/python/plotly/plotly/figure_factory/_streamline.py index caf42d704e4..23be4210e46 100644 --- a/packages/python/plotly/plotly/figure_factory/_streamline.py +++ b/packages/python/plotly/plotly/figure_factory/_streamline.py @@ -62,6 +62,7 @@ def create_streamline( Example 1: Plot simple streamline and increase arrow size >>> from plotly.figure_factory import create_streamline + >>> import plotly.graph_objects as go >>> import numpy as np >>> import math @@ -102,10 +103,10 @@ def create_streamline( >>> fig = create_streamline(x, y, u_s, v_s, density=2, name='streamline') >>> # Add source point - >>> point = Scatter(x=[x_s], y=[y_s], mode='markers', - ... marker=Marker(size=14), name='source point') + >>> point = go.Scatter(x=[x_s], y=[y_s], mode='markers', + ... marker_size=14, name='source point') - >>> fig['data'].append(point) + >>> fig.add_trace(point) # doctest: +SKIP >>> fig.show() """ utils.validate_equal_length(x, y) diff --git a/packages/python/plotly/plotly/figure_factory/_table.py b/packages/python/plotly/plotly/figure_factory/_table.py index 8e3087410d0..c0eec1fb2bd 100644 --- a/packages/python/plotly/plotly/figure_factory/_table.py +++ b/packages/python/plotly/plotly/figure_factory/_table.py @@ -36,7 +36,10 @@ def create_table( **kwargs ): """ - BETA function that creates data tables + Function that creates data tables. + + See also the plotly.graph_objects trace + :class:`plotly.graph_objects.Table` :param (pandas.Dataframe | list[list]) text: data for table. :param (str|list[list]) colorscale: Colorscale for table where the @@ -73,13 +76,11 @@ def create_table( Example 2: Table with Custom Coloring >>> from plotly.figure_factory import create_table - >>> text = [['Country', 'Year', 'Population'], ... ['US', 2000, 282200000], ... ['Canada', 2000, 27790000], ... ['US', 2010, 309000000], ... ['Canada', 2010, 34000000]] - >>> table = create_table(text, ... colorscale=[[0, '#000000'], ... [.5, '#80beff'], @@ -92,12 +93,11 @@ def create_table( >>> from plotly.figure_factory import create_table >>> import pandas as pd - >>> df = pd.read_csv('http://www.stat.ubc.ca/~jenny/notOcto/STAT545A/examples/gapminder/data/gapminderDataFiveYear.txt', sep='\t') >>> df_p = df[0:25] - >>> table_simple = create_table(df_p) >>> table_simple.show() + """ # Avoiding mutables in the call signature diff --git a/packages/python/plotly/plotly/figure_factory/_ternary_contour.py b/packages/python/plotly/plotly/figure_factory/_ternary_contour.py index e48fea65673..49d1e60dc68 100644 --- a/packages/python/plotly/plotly/figure_factory/_ternary_contour.py +++ b/packages/python/plotly/plotly/figure_factory/_ternary_contour.py @@ -584,33 +584,33 @@ def create_ternary_contour( >>> c = 1 - a - b >>> # Values to be displayed as contours >>> z = a * b * c - >>> fig = ff.create_ternarycontour(np.stack((a, b, c)), z) + >>> fig = ff.create_ternary_contour(np.stack((a, b, c)), z) >>> fig.show() It is also possible to give only two barycentric coordinates for each point, since the sum of the three coordinates is one: - >>> fig = ff.create_ternarycontour(np.stack((a, b)), z) + >>> fig = ff.create_ternary_contour(np.stack((a, b)), z) Example 2: ternary contour plot with line contours - >>> fig = ff.create_ternarycontour(np.stack((a, b, c)), z, coloring='lines') + >>> fig = ff.create_ternary_contour(np.stack((a, b, c)), z, coloring='lines') Example 3: customize number of contours - >>> fig = ff.create_ternarycontour(np.stack((a, b, c)), z, ncontours=8) + >>> fig = ff.create_ternary_contour(np.stack((a, b, c)), z, ncontours=8) Example 4: superimpose contour plot and original data as markers - >>> fig = ff.create_ternarycontour(np.stack((a, b, c)), z, coloring='lines', - showmarkers=True) + >>> fig = ff.create_ternary_contour(np.stack((a, b, c)), z, coloring='lines', + ... showmarkers=True) Example 5: customize title and pole labels - >>> fig = ff.create_ternarycontour(np.stack((a, b, c)), z, - ... title='Ternary plot', - ... pole_labels=['clay', 'quartz', 'fledspar']) + >>> fig = ff.create_ternary_contour(np.stack((a, b, c)), z, + ... title='Ternary plot', + ... pole_labels=['clay', 'quartz', 'fledspar']) """ if scipy_interp is None: raise ImportError( diff --git a/packages/python/plotly/plotly/figure_factory/_trisurf.py b/packages/python/plotly/plotly/figure_factory/_trisurf.py index caf7353d837..f3f55d8d1e0 100644 --- a/packages/python/plotly/plotly/figure_factory/_trisurf.py +++ b/packages/python/plotly/plotly/figure_factory/_trisurf.py @@ -456,7 +456,7 @@ def create_trisurf( >>> color_choices = ['rgb(0, 0, 0)', '#6c4774', '#d6c7dd'] >>> for index in range(len(simplices)): - >>> colors.append(random.choice(color_choices)) + ... colors.append(random.choice(color_choices)) >>> fig = create_trisurf( ... x, y, z, simplices, diff --git a/packages/python/plotly/plotly/figure_factory/_violin.py b/packages/python/plotly/plotly/figure_factory/_violin.py index c2bc612cfce..d7ac7a8f2a0 100644 --- a/packages/python/plotly/plotly/figure_factory/_violin.py +++ b/packages/python/plotly/plotly/figure_factory/_violin.py @@ -451,7 +451,8 @@ def create_violin( title="Violin and Rug Plot", ): """ - Returns figure for a violin plot + **deprecated**, use instead the plotly.graph_objects trace + :class:`plotly.graph_objects.Violin`. :param (list|array) data: accepts either a list of numerical values, a list of dictionaries all with identical keys and at least one @@ -496,7 +497,6 @@ def create_violin( >>> # create list of random values >>> data_list = np.random.randn(100) - >>> data_list.tolist() >>> # create violin fig >>> fig = create_violin(data_list, colors='#604d9e') diff --git a/packages/python/plotly/plotly/graph_objs/__init__.py b/packages/python/plotly/plotly/graph_objs/__init__.py index 140fd58fccc..9a204d2dbbf 100644 --- a/packages/python/plotly/plotly/graph_objs/__init__.py +++ b/packages/python/plotly/plotly/graph_objs/__init__.py @@ -95064,27 +95064,31 @@ def template(self): annotation or a logo image, for example. To omit one of these items on the plot, make an item with matching `templateitemname` and `visible: false`. - + The 'template' property is an instance of Template that may be specified as: - An instance of plotly.graph_objs.layout.Template - A dict of string/value properties that will be passed to the Template constructor - + Supported dict properties: - + data plotly.graph_objects.layout.template.Data instance or dict with compatible properties layout plotly.graph_objects.Layout instance or dict with compatible properties - + - The name of a registered template where current registered templates are stored in the plotly.io.templates configuration object. The names of all registered templates can be retrieved with: + >>> import plotly.io as pio - >>> list(pio.templates) + >>> list(pio.templates) # doctest: +ELLIPSIS + ['ggplot2', 'seaborn', 'simple_white', 'plotly', 'plotly_white', 'plotly_dark', ...] + + - A string containing multiple registered template names, joined on '+' characters (e.g. 'template1+template2'). In this case the resulting template is computed by merging together the collection of registered diff --git a/packages/python/plotly/plotly/io/_templates.py b/packages/python/plotly/plotly/io/_templates.py index 8395a20dffb..f9f399a1b24 100644 --- a/packages/python/plotly/plotly/io/_templates.py +++ b/packages/python/plotly/plotly/io/_templates.py @@ -375,37 +375,37 @@ def to_templated(fig, skip=("title", "text")): Construct a figure with large courier text >>> fig = go.Figure(layout={'title': 'Figure Title', - ... 'font': {'size': 20, 'family': 'Courier'}}) - >>> fig + ... 'font': {'size': 20, 'family': 'Courier'}, + ... 'template':"none"}) + >>> fig # doctest: +NORMALIZE_WHITESPACE Figure({ 'data': [], - 'layout': {'title': 'Figure Title', - 'font': {'family': 'Courier', 'size': 20}} + 'layout': {'font': {'family': 'Courier', 'size': 20}, + 'template': '...', 'title': {'text': 'Figure Title'}} }) Convert to a figure with a template. Note how the 'font' properties have been moved into the template property. >>> templated_fig = pio.to_templated(fig) + >>> templated_fig.layout.template + layout.Template({ + 'data': {}, 'layout': {'font': {'family': 'Courier', 'size': 20}} + }) >>> templated_fig Figure({ - 'data': [], - 'layout': {'title': 'Figure Title', - 'template': {'layout': {'font': {'family': 'Courier', - 'size': 20}}}} + 'data': [], 'layout': {'template': '...', 'title': {'text': 'Figure Title'}} }) + Next create a new figure with this template >>> fig2 = go.Figure(layout={ ... 'title': 'Figure 2 Title', ... 'template': templated_fig.layout.template}) - >>> fig2 - Figure({ - 'data': [], - 'layout': {'title': 'Figure 2 Title', - 'template': {'layout': {'font': {'family': 'Courier', - 'size': 20}}}} + >>> fig2.layout.template + layout.Template({ + 'layout': {'font': {'family': 'Courier', 'size': 20}} }) The default font in fig2 will now be size 20 Courier. @@ -418,23 +418,16 @@ def to_templated(fig, skip=("title", "text")): >>> go.Figure(layout={ ... 'title': 'Figure 3 Title', - ... 'template': 'large_courier'}) - Figure({ - 'data': [], - 'layout': {'title': 'Figure 3 Title', - 'template': {'layout': {'font': {'family': 'Courier', - 'size': 20}}}} - }) + ... 'template': 'large_courier'}) # doctest: +ELLIPSIS + Figure(...) Finally, set this as the default template to be applied to all new figures >>> pio.templates.default = 'large_courier' - >>> go.Figure(layout={'title': 'Figure 4 Title'}) - Figure({ - 'data': [], - 'layout': {'title': 'Figure 4 Title', - 'template': {'layout': {'font': {'family': 'Courier', - 'size': 20}}}} + >>> fig = go.Figure(layout={'title': 'Figure 4 Title'}) + >>> fig.layout.template + layout.Template({ + 'layout': {'font': {'family': 'Courier', 'size': 20}} }) Returns diff --git a/packages/python/plotly/plotly/offline/offline.py b/packages/python/plotly/plotly/offline/offline.py index c7d458b1452..30674ee19da 100644 --- a/packages/python/plotly/plotly/offline/offline.py +++ b/packages/python/plotly/plotly/offline/offline.py @@ -81,10 +81,10 @@ def get_plotlyjs(): ... {div2} ... ... - ...'''.format(plotlyjs=get_plotlyjs(), div1=div1, div2=div2) + ... '''.format(plotlyjs=get_plotlyjs(), div1=div1, div2=div2) >>> with open('multi_plot.html', 'w') as f: - ... f.write(html) + ... f.write(html) # doctest: +SKIP """ path = os.path.join("package_data", "plotly.min.js") plotlyjs = pkgutil.get_data("plotly", path).decode("utf-8") diff --git a/packages/python/plotly/plotly/subplots.py b/packages/python/plotly/plotly/subplots.py index 63adab47e3a..9f2075e7cb1 100644 --- a/packages/python/plotly/plotly/subplots.py +++ b/packages/python/plotly/plotly/subplots.py @@ -235,15 +235,17 @@ def make_subplots( >>> # Stack two subplots vertically, and add a scatter trace to each >>> from plotly.subplots import make_subplots - ... import plotly.graph_objs as go - ... fig = make_subplots(rows=2) + >>> import plotly.graph_objects as go + >>> fig = make_subplots(rows=2) This is the format of your plot grid: [ (1,1) xaxis1,yaxis1 ] [ (2,1) xaxis2,yaxis2 ] - >>> fig.add_scatter(y=[2, 1, 3], row=1, col=1) - ... fig.add_scatter(y=[1, 3, 2], row=2, col=1) + >>> fig.add_scatter(y=[2, 1, 3], row=1, col=1) # doctest: +ELLIPSIS + Figure(...) + >>> fig.add_scatter(y=[1, 3, 2], row=2, col=1) # doctest: +ELLIPSIS + Figure(...) or see Figure.append_trace @@ -256,23 +258,28 @@ def make_subplots( [ (1,1) xaxis1,yaxis1 ] [ (2,1) xaxis2,yaxis2 ] - >>> fig.add_scatter(y=[2, 1, 3], row=1, col=1) - ... fig.add_scatter(y=[1, 3, 2], row=2, col=1) + >>> fig.add_scatter(y=[2, 1, 3], row=1, col=1) # doctest: +ELLIPSIS + Figure(...) + >>> fig.add_scatter(y=[1, 3, 2], row=2, col=1) # doctest: +ELLIPSIS + Figure(...) Example 3: >>> # irregular subplot layout (more examples below under 'specs') >>> fig = make_subplots(rows=2, cols=2, - specs=[[{}, {}], - [{'colspan': 2}, None]]) + ... specs=[[{}, {}], + ... [{'colspan': 2}, None]]) This is the format of your plot grid: [ (1,1) xaxis1,yaxis1 ] [ (1,2) xaxis2,yaxis2 ] [ (2,1) xaxis3,yaxis3 - ] - >>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2]), row=1, col=1) - ... fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2]), row=1, col=2) - ... fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2]), row=2, col=1) + >>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2]), row=1, col=1) # doctest: +ELLIPSIS + Figure(...) + >>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2]), row=1, col=2) # doctest: +ELLIPSIS + Figure(...) + >>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2]), row=2, col=1) # doctest: +ELLIPSIS + Figure(...) Example 4: @@ -285,8 +292,10 @@ def make_subplots( With insets: [ xaxis2,yaxis2 ] over [ (1,1) xaxis1,yaxis1 ] - >>> fig.add_scatter(x=[1,2,3], y=[2,1,1]) - ... fig.add_scatter(x=[1,2,3], y=[2,1,2], xaxis='x2', yaxis='y2') + >>> fig.add_scatter(x=[1,2,3], y=[2,1,1]) # doctest: +ELLIPSIS + Figure(...) + >>> fig.add_scatter(x=[1,2,3], y=[2,1,2], xaxis='x2', yaxis='y2') # doctest: +ELLIPSIS + Figure(...) Example 5: @@ -297,8 +306,10 @@ def make_subplots( [ (1,1) x1,y1 ] [ (2,1) x2,y2 ] - >>> fig.add_scatter(x=[1,2,3], y=[2,1,2], row=1, col=1) - >>> fig.add_bar(x=[1,2,3], y=[2,1,2], row=2, col=1) + >>> fig.add_scatter(x=[1,2,3], y=[2,1,2], row=1, col=1) # doctest: +ELLIPSIS + Figure(...) + >>> fig.add_bar(x=[1,2,3], y=[2,1,2], row=2, col=1) # doctest: +ELLIPSIS + Figure(...) Example 6: @@ -316,7 +327,8 @@ def make_subplots( ... b=[0.2, 0.3, 0.1], ... c=[0.7, 0.5, 0.8])], ... rows=[1, 1, 2, 2], - ... cols=[1, 2, 1, 2]) + ... cols=[1, 2, 1, 2]) # doctest: +ELLIPSIS + Figure(...) """ import plotly.graph_objs as go diff --git a/packages/python/plotly/plotly/tests/test_core/test_subplots/__init__.py b/packages/python/plotly/plotly/tests/test_core/test_subplots/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/python/plotly/plotly/tests/test_optional/test_subplots/__init__.py b/packages/python/plotly/plotly/tests/test_optional/test_subplots/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/python/plotly/plotly/utils.py b/packages/python/plotly/plotly/utils.py index bf58ff756a1..0af0a49f710 100644 --- a/packages/python/plotly/plotly/utils.py +++ b/packages/python/plotly/plotly/utils.py @@ -149,9 +149,9 @@ def node_generator(node, path=()): Example: >>> for node, path in node_generator({'a': {'b': 5}}): - >>> print node, path + ... print(node, path) {'a': {'b': 5}} () - {'b': 5} ('a', ) + {'b': 5} ('a',) """ if not isinstance(node, dict): @@ -176,8 +176,8 @@ def get_by_path(obj, path): >>> figure = {'data': [{'x': [5]}]} >>> path = ('data', 0, 'x') - >>> get_by_path(figure, path) # [5] - + >>> get_by_path(figure, path) + [5] """ for key in path: obj = obj[key]