diff --git a/.circleci/config.yml b/.circleci/config.yml index 2973d204991..3397c643041 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -448,7 +448,7 @@ jobs: docker: # specify the version you desire here # use `-browsers` prefix for selenium tests, for example, `3.9-browsers` - - image: cimg/python:3.9-browsers + - image: cimg/python:3.10-browsers steps: - add_ssh_keys: diff --git a/binder/requirements.txt b/binder/requirements.txt index a65f74694d2..3a47a0acdfb 100644 --- a/binder/requirements.txt +++ b/binder/requirements.txt @@ -2,10 +2,10 @@ jupytext plotly==5.22.0 jupyter notebook -pandas==1.2.0 -statsmodels==0.12.1 +pandas==2.2.2 +statsmodels==0.14.2 scipy -patsy==0.5.1 +patsy==0.5.6 numpy plotly-geo psutil diff --git a/doc/python/3d-volume.md b/doc/python/3d-volume.md index 5dde49cf63c..c92bd4fb479 100644 --- a/doc/python/3d-volume.md +++ b/doc/python/3d-volume.md @@ -86,7 +86,7 @@ np.random.seed(0) l = 30 X, Y, Z = np.mgrid[:l, :l, :l] vol = np.zeros((l, l, l)) -pts = (l * np.random.rand(3, 15)).astype(np.int) +pts = (l * np.random.rand(3, 15)).astype(int) vol[tuple(indices for indices in pts)] = 1 from scipy import ndimage vol = ndimage.gaussian_filter(vol, 4) diff --git a/doc/python/axes.md b/doc/python/axes.md index 9c4fd1acbed..9a6ba71bbda 100644 --- a/doc/python/axes.md +++ b/doc/python/axes.md @@ -367,7 +367,7 @@ fig.show() *New in 5.19* -If `tickangle` is not explicitly set, its default value is `auto`, meaning if the label needs to be rotated to avoid labels overlapping, it will rotate by either 30 or 90 degrees. Using `autotickangles`, you can also specify a list of angles for `tickangle` to use. If `tickangle` is `auto` and you provide a list of angles to `autotickangles`, the label angle will be set to the first value in the list that prevents overlap. +If `tickangle` is not explicitly set, its default value is `auto`, meaning if the label needs to be rotated to avoid labels overlapping, it will rotate by either 30 or 90 degrees. Using `autotickangles`, you can also specify a list of angles for `tickangle` to use. If `tickangle` is `auto` and you provide a list of angles to `autotickangles`, the label angle will be set to the first value in the list that prevents overlap. ```python import plotly.express as px @@ -390,14 +390,18 @@ Here is an example. import plotly.graph_objects as go import pandas as pd -# Load and filter Apple stock data for 2016 apple_df = pd.read_csv( - "https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv", - parse_dates=["Date"], - index_col="Date" + "https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv" ) -apple_df_2016 = apple_df["2016"] +# Convert 'Date' column to datetime format +apple_df['Date'] = pd.to_datetime(apple_df['Date']) + +# Set 'Date' column as index +apple_df.set_index('Date', inplace=True) + +# Filter for 2016 +apple_df_2016 = apple_df.loc['2016'] # Create figure and add line fig = go.Figure() @@ -599,7 +603,7 @@ fig.show() *New in 5.17* -You can also set just a lower or upper bound manually and have autorange applied to the other bound by setting it to `None`. In the following example, we set a an upper bound of 4.5 on the x axes, while specifying `None` for the lower bound, meaning it will use autorange. On the y axes, we set the lower bound, and use `None` for the upper bound, meaning that uses autorange. +You can also set just a lower or upper bound manually and have autorange applied to the other bound by setting it to `None`. In the following example, we set a an upper bound of 4.5 on the x axes, while specifying `None` for the lower bound, meaning it will use autorange. On the y axes, we set the lower bound, and use `None` for the upper bound, meaning that uses autorange. ```python import plotly.express as px @@ -857,7 +861,7 @@ fig.show() #### nonnegative, tozero, and normal Rangemode -When you don't specify a range, autorange is used. It's also used for bounds set to `None` when providing a `range`. +When you don't specify a range, autorange is used. It's also used for bounds set to `None` when providing a `range`. The axis auto-range calculation logic can be configured using the `rangemode` axis parameter. @@ -898,7 +902,7 @@ fig.update_xaxes(autorangeoptions=dict(maxallowed=5)) fig.show() ``` -##### Clip Minimum and Maximum +##### Clip Minimum and Maximum You can also clip an axis range at a specific maximum or minimum value with `autorangeoptions.clipmax` and `autorangeoptions.clipmin`. @@ -916,7 +920,7 @@ fig.show() ##### Specify Values to be Included -Use `autorangeoptions.include` to specify a value that should always be included within the calculated autorange. In this example, we specify that for the autorange calculated on the x-axis, 5 should be included. +Use `autorangeoptions.include` to specify a value that should always be included within the calculated autorange. In this example, we specify that for the autorange calculated on the x-axis, 5 should be included. ```python import plotly.express as px diff --git a/doc/python/box-plots.md b/doc/python/box-plots.md index a22762c0750..dbaca729096 100644 --- a/doc/python/box-plots.md +++ b/doc/python/box-plots.md @@ -458,12 +458,12 @@ x_data = ['Carmelo Anthony', 'Dwyane Wade', N = 50 -y0 = (10 * np.random.randn(N) + 30).astype(np.int) -y1 = (13 * np.random.randn(N) + 38).astype(np.int) -y2 = (11 * np.random.randn(N) + 33).astype(np.int) -y3 = (9 * np.random.randn(N) + 36).astype(np.int) -y4 = (15 * np.random.randn(N) + 31).astype(np.int) -y5 = (12 * np.random.randn(N) + 40).astype(np.int) +y0 = (10 * np.random.randn(N) + 30).astype(int) +y1 = (13 * np.random.randn(N) + 38).astype(int) +y2 = (11 * np.random.randn(N) + 33).astype(int) +y3 = (9 * np.random.randn(N) + 36).astype(int) +y4 = (15 * np.random.randn(N) + 31).astype(int) +y5 = (12 * np.random.randn(N) + 40).astype(int) y_data = [y0, y1, y2, y3, y4, y5] diff --git a/doc/python/icicle-charts.md b/doc/python/icicle-charts.md index 540f9f7e82c..38569a7ea03 100644 --- a/doc/python/icicle-charts.md +++ b/doc/python/icicle-charts.md @@ -305,7 +305,7 @@ def build_hierarchical_dataframe(df, levels, value_column, color_columns=None): Levels are given starting from the bottom to the top of the hierarchy, ie the last level corresponds to the root. """ - df_all_trees = pd.DataFrame(columns=['id', 'parent', 'value', 'color']) + df_list = [] for i, level in enumerate(levels): df_tree = pd.DataFrame(columns=['id', 'parent', 'value', 'color']) dfg = df.groupby(levels[i:]).sum() @@ -317,11 +317,12 @@ def build_hierarchical_dataframe(df, levels, value_column, color_columns=None): df_tree['parent'] = 'total' df_tree['value'] = dfg[value_column] df_tree['color'] = dfg[color_columns[0]] / dfg[color_columns[1]] - df_all_trees = df_all_trees.append(df_tree, ignore_index=True) + df_list.append(df_tree) total = pd.Series(dict(id='total', parent='', value=df[value_column].sum(), - color=df[color_columns[0]].sum() / df[color_columns[1]].sum())) - df_all_trees = df_all_trees.append(total, ignore_index=True) + color=df[color_columns[0]].sum() / df[color_columns[1]].sum()), name=0) + df_list.append(total) + df_all_trees = pd.concat(df_list, ignore_index=True) return df_all_trees diff --git a/doc/python/mixed-subplots.md b/doc/python/mixed-subplots.md index 13737b5f6d1..24ee5123beb 100644 --- a/doc/python/mixed-subplots.md +++ b/doc/python/mixed-subplots.md @@ -55,8 +55,8 @@ df = pd.read_csv( ) # frequency of Country -freq = df -freq = freq.Country.value_counts().reset_index().rename(columns={"index": "x"}) +freq = df['Country'].value_counts().reset_index() +freq.columns = ['x', 'Country'] # read in 3d volcano surface data df_v = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/volcano.csv") diff --git a/doc/python/ml-regression.md b/doc/python/ml-regression.md index b8be347943a..c74b49e92bd 100644 --- a/doc/python/ml-regression.md +++ b/doc/python/ml-regression.md @@ -120,7 +120,7 @@ from sklearn.linear_model import LinearRegression from sklearn.model_selection import train_test_split df = px.data.tips() -X = df.total_bill[:, None] +X = df.total_bill.to_numpy()[:, None] X_train, X_test, y_train, y_test = train_test_split(X, df.tip, random_state=0) model = LinearRegression() @@ -129,7 +129,6 @@ model.fit(X_train, y_train) x_range = np.linspace(X.min(), X.max(), 100) y_range = model.predict(x_range.reshape(-1, 1)) - fig = go.Figure([ go.Scatter(x=X_train.squeeze(), y=y_train, name='train', mode='markers'), go.Scatter(x=X_test.squeeze(), y=y_test, name='test', mode='markers'), diff --git a/doc/python/sunburst-charts.md b/doc/python/sunburst-charts.md index e22f9f9dd7b..06cfb38e57d 100644 --- a/doc/python/sunburst-charts.md +++ b/doc/python/sunburst-charts.md @@ -355,7 +355,7 @@ def build_hierarchical_dataframe(df, levels, value_column, color_columns=None): Levels are given starting from the bottom to the top of the hierarchy, ie the last level corresponds to the root. """ - df_all_trees = pd.DataFrame(columns=['id', 'parent', 'value', 'color']) + df_list = [] for i, level in enumerate(levels): df_tree = pd.DataFrame(columns=['id', 'parent', 'value', 'color']) dfg = df.groupby(levels[i:]).sum() @@ -367,11 +367,12 @@ def build_hierarchical_dataframe(df, levels, value_column, color_columns=None): df_tree['parent'] = 'total' df_tree['value'] = dfg[value_column] df_tree['color'] = dfg[color_columns[0]] / dfg[color_columns[1]] - df_all_trees = df_all_trees.append(df_tree, ignore_index=True) + df_list.append(df_tree) total = pd.Series(dict(id='total', parent='', value=df[value_column].sum(), - color=df[color_columns[0]].sum() / df[color_columns[1]].sum())) - df_all_trees = df_all_trees.append(total, ignore_index=True) + color=df[color_columns[0]].sum() / df[color_columns[1]].sum()), name=0) + df_list.append(total) + df_all_trees = pd.concat(df_list, ignore_index=True) return df_all_trees diff --git a/doc/python/treemaps.md b/doc/python/treemaps.md index 98fbeadcd40..6671698cb93 100644 --- a/doc/python/treemaps.md +++ b/doc/python/treemaps.md @@ -90,7 +90,7 @@ When the argument of `color` corresponds to non-numerical data, discrete colors ```python import plotly.express as px df = px.data.tips() -fig = px.treemap(df, path=[px.Constant("all"), 'sex', 'day', 'time'], +fig = px.treemap(df, path=[px.Constant("all"), 'sex', 'day', 'time'], values='total_bill', color='day') fig.update_layout(margin = dict(t=50, l=25, r=25, b=25)) fig.show() @@ -101,7 +101,7 @@ In the example below the color of Saturday and Sunday sectors is the same as Din ```python import plotly.express as px df = px.data.tips() -fig = px.treemap(df, path=[px.Constant("all"), 'sex', 'day', 'time'], +fig = px.treemap(df, path=[px.Constant("all"), 'sex', 'day', 'time'], values='total_bill', color='time') fig.update_layout(margin = dict(t=50, l=25, r=25, b=25)) fig.show() @@ -114,7 +114,7 @@ For more information about discrete colors, see the [dedicated page](/python/dis ```python import plotly.express as px df = px.data.tips() -fig = px.treemap(df, path=[px.Constant("all"), 'sex', 'day', 'time'], +fig = px.treemap(df, path=[px.Constant("all"), 'sex', 'day', 'time'], values='total_bill', color='time', color_discrete_map={'(?)':'lightgrey', 'Lunch':'gold', 'Dinner':'darkblue'}) fig.update_layout(margin = dict(t=50, l=25, r=25, b=25)) @@ -241,7 +241,7 @@ fig = go.Figure(go.Treemap( labels = labels, values = values, parents = parents, - marker_colors = ["pink", "royalblue", "lightgray", "purple", + marker_colors = ["pink", "royalblue", "lightgray", "purple", "cyan", "lightgray", "lightblue", "lightgreen"] )) @@ -316,7 +316,7 @@ def build_hierarchical_dataframe(df, levels, value_column, color_columns=None): Levels are given starting from the bottom to the top of the hierarchy, ie the last level corresponds to the root. """ - df_all_trees = pd.DataFrame(columns=['id', 'parent', 'value', 'color']) + df_list = [] for i, level in enumerate(levels): df_tree = pd.DataFrame(columns=['id', 'parent', 'value', 'color']) dfg = df.groupby(levels[i:]).sum() @@ -328,11 +328,12 @@ def build_hierarchical_dataframe(df, levels, value_column, color_columns=None): df_tree['parent'] = 'total' df_tree['value'] = dfg[value_column] df_tree['color'] = dfg[color_columns[0]] / dfg[color_columns[1]] - df_all_trees = df_all_trees.append(df_tree, ignore_index=True) + df_list.append(df_tree) total = pd.Series(dict(id='total', parent='', value=df[value_column].sum(), - color=df[color_columns[0]].sum() / df[color_columns[1]].sum())) - df_all_trees = df_all_trees.append(total, ignore_index=True) + color=df[color_columns[0]].sum() / df[color_columns[1]].sum()), name=0) + df_list.append(total) + df_all_trees = pd.concat(df_list, ignore_index=True) return df_all_trees diff --git a/doc/requirements.txt b/doc/requirements.txt index 0d4ae8d2edd..952ab4a102b 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -4,21 +4,21 @@ ipywidgets==7.7.2 jupyter-client<7 jupyter notebook -pandas==1.2.0 -statsmodels==0.12.1 -scipy==1.5.4 -patsy==0.5.1 -numpy==1.19.5 +pandas==2.2.2 +statsmodels==0.14.2 +scipy==1.13.0 +patsy==0.5.6 +numpy==1.26.4 plotly-geo igraph -geopandas==0.8.1 -pyshp==2.1.2 -shapely==1.7.1 +geopandas==0.14.3 +pyshp==2.3.1 +shapely==2.0.4 psutil requests -networkx==2.6.3 +networkx==3.3 squarify -scikit-image==0.18.1 +scikit-image==0.23.2 scikit-learn sphinx==3.5.4 sphinxcontrib-applehelp==1.0.2 @@ -31,7 +31,7 @@ sphinx_bootstrap_theme recommonmark pathlib python-frontmatter -datashader==0.14.4 +datashader==0.16.1 pyarrow cufflinks==0.17.3 kaleido @@ -42,7 +42,6 @@ nbconvert==5.6.1 orjson dash-bio jinja2<3.1 -parmed<=3.4.4; python_version<"3.8" -dask==2022.2.0 +dask==2024.4.2 polars -geoparse<=2.0.3 +xarray==2022.9.0