### Display HTML and Install Packages Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/change-callbacks-datashader.md Use IPython.display to render HTML content and the '!' prefix to execute shell commands like pip install within a notebook. This example installs the plotly publisher package. ```python from IPython.display import display, HTML display(HTML('')) display(HTML('')) ! pip install git+https://github.com/plotly/publisher.git --upgrade import publisher publisher.publish( 'change-callbacks-datashader.ipynb', 'python/change-callbacks-datashader/', 'FigureWidget | plotly', 'Display Large Datasets with DataShader and Change Callbacks', title = 'DataShader Case Study', name = 'DataShader Case Study', uses_plotly_offline=True, has_thumbnail='true', thumbnail='thumbnail/ipython_widgets.jpg', language='python', page_type='example_index', order=24, ipynb= '~notebook_demo/239') ``` -------------------------------- ### Publish Baseline Detection Example Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/baseline-detection.md This snippet is used for publishing the example notebook. It installs the `publisher` package and then uses it to publish the notebook with specified metadata. Ensure the notebook file exists at the specified path. ```python from IPython.display import display, HTML display(HTML('')) display(HTML('')) ! pip install git+https://github.com/plotly/publisher.git --upgrade import publisher publisher.publish( 'python-Baseline-Detection.ipynb', 'python/baseline-detection/', 'Baseline Detection | plotly', 'Learn how to detect baselines on data in Python.', title='Baseline Detection in Python | plotly', name='Baseline Detection', language='python', page_type='example_index', has_thumbnail='false', display_as='peak-analysis', order=1, ipynb= '~notebook_demo/117') ``` -------------------------------- ### Publish notebook example Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/interact-decorator.md Configure and run the publisher utility to deploy the notebook example. ```python from IPython.display import display, HTML display(HTML('')) display(HTML('')) ! pip install git+https://github.com/plotly/publisher.git --upgrade import publisher publisher.publish( 'Interact.ipynb', 'python/interact-decorator/', 'Use the Interact decorator with go.FigureWidget', 'Use the Interact decorator with go.FigureWidget', title = 'Use Interact decorator with FigureWidget', name = 'Use Interact decorator with FigureWidget', has_thumbnail='true', thumbnail='thumbnail/zoom.jpg', language='python', page_type='example_index', display_as='chart_events', order=4, ipynb= '~notebook_demo/254') ``` -------------------------------- ### Setup Display and Install Publisher Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/filled-area-animation.md This snippet configures the IPython display environment with custom fonts and stylesheets, and installs the Plotly publisher package. Ensure you have git and pip installed. ```python from IPython.display import display, HTML display(HTML('')) display(HTML('')) !pip install git+https://github.com/plotly/publisher.git --upgrade ``` -------------------------------- ### Install and Publish Plotly Content Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/apache-spark.md Installs the Plotly publisher package from GitHub and publishes a Jupyter notebook as a Plotly example. This is used for creating documentation and tutorials. ```python ! pip install git+https://github.com/plotly/publisher.git --upgrade import publisher publisher.publish( 'apachespark.ipynb', 'python/apache-spark/', 'Plot Data from Apache Spark', 'A tutorial showing how to plot Apache Spark DataFrames with Plotly', title='Plotting Spark DataFrames | Plotly', has_thumbnail='false', language='python', page_type='example_index', display_as='databases', order=2, redirect_from= 'ipython-notebooks/apache-spark/') ``` -------------------------------- ### Install Documentation Dependencies Source: https://github.com/plotly/plotly.py/blob/main/doc/README.md Sets up a Python virtual environment and installs the necessary packages for building the plotly.py documentation. ```bash cd doc uv venv --python 3.9 source .venv/bin/activate uv pip install -r requirements.txt ``` -------------------------------- ### Publish Plotly Notebook Example Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/statistics-charts.md This snippet is for publishing Plotly notebook examples. It installs the publisher package and then uses it to publish a specified notebook, setting various metadata for the online documentation. ```python from IPython.display import display, HTML display(HTML('')) display(HTML('')) ! pip install git+https://github.com/plotly/publisher.git --upgrade import publisher publisher.publish( 'python-Statistics-Charts.ipynb', 'python/statistics-charts/', 'Statistics Charts | plotly', 'Learn how to plot statistical data with various charts using Python.', title='Statistics Charts in Python. | plotly', name='Statistics Charts', language='python', page_type='example_index', has_thumbnail='false', display_as='statistics', order=5, ipynb= '~notebook_demo/116') ``` -------------------------------- ### Create a basic bar chart with plotly.py Source: https://github.com/plotly/plotly.py/blob/main/README.md This example demonstrates how to create a simple bar chart using plotly.express. Ensure plotly is installed before running. ```python import plotly.express as px fig = px.bar(x=["a", "b", "c"], y=[1, 3, 2]) fig.show() ``` -------------------------------- ### Install Doc Dependencies Source: https://github.com/plotly/plotly.py/blob/main/doc/README.md Installs documentation dependencies using uv pip within the doc/ directory. ```bash uv pip install -r requirements.txt ``` -------------------------------- ### Install Development Packages with uv Source: https://github.com/plotly/plotly.py/blob/main/CONTRIBUTING.md Use this command to install all necessary packages for development and testing if you are using uv. ```bash uv sync --extra dev ``` -------------------------------- ### Publish Plotly Notebook Example Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/polygon-area.md This snippet demonstrates how to publish a Plotly notebook example using the `publisher` library. It installs the library, imports it, and then calls the `publish` function with various parameters to configure the publication. ```python from IPython.display import display, HTML display(HTML('')) display(HTML('')) ! pip install git+https://github.com/plotly/publisher.git --upgrade import publisher publisher.publish( 'python_Polygon_Area.ipynb', 'python/polygon-area/', 'Polygon Area | plotly', 'Learn how to find the area of any simple polygon', title='Polygon Area in Python. | plotly', name='Polygon Area', language='python', page_type='example_index', has_thumbnail='false', display_as='mathematics', order=8, ipynb= '~notebook_demo/100') ``` -------------------------------- ### Install Development Packages with pip Source: https://github.com/plotly/plotly.py/blob/main/CONTRIBUTING.md Install all packages for development and testing using pip, especially if uv sync does not work as expected. ```bash pip install -e '.[dev]' ``` -------------------------------- ### Install Kaleido for Static Image Export Source: https://github.com/plotly/plotly.py/blob/main/doc/python/getting-started.md Install the Kaleido package for static image export. ```bash pip install --upgrade kaleido ``` ```bash conda install -c plotly python-kaleido ``` -------------------------------- ### Install JupyterLab and Anywidget Source: https://github.com/plotly/plotly.py/blob/main/doc/python/getting-started.md Install necessary packages for Plotly support in JupyterLab. ```bash pip install jupyterlab anywidget ``` ```bash conda install jupyterlab anywidget ``` -------------------------------- ### Install Orca on Google Colab Source: https://github.com/plotly/plotly.py/blob/main/doc/python/orca-management.md Commands to set up the environment and install Orca on a Google Colab instance. ```bash !pip install plotly>=4.7.1 !wget https://github.com/plotly/orca/releases/download/v1.2.1/orca-1.2.1-x86_64.AppImage -O /usr/local/bin/orca !chmod +x /usr/local/bin/orca !apt-get install xvfb libgtk2.0-0 libgconf-2-4 ``` -------------------------------- ### Install Jupyter and anywidget using conda Source: https://github.com/plotly/plotly.py/blob/main/README.md Alternative installation for Jupyter widget support using conda. ```bash conda install jupyter anywidget ``` -------------------------------- ### Setup Display and Publish Notebook Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/heatmap-animation.md This snippet configures the display environment for Plotly notebooks and publishes the notebook using the 'publisher' library. Ensure 'publisher' is installed and the notebook path is correct before running. ```python from IPython.display import display, HTML display(HTML('')) display(HTML('')) !pip install git+https://github.com/plotly/publisher.git --upgrade import publisher publisher.publish( 'heatmap.ipynb', 'python/heatmap-animation/', 'Heatmap Animation | plotly', 'How to make an animated heatmap in Python.', title='Heatmap Animation | plotly', name='Heatmap Animation', language='python', page_type='example_index', has_thumbnail='true', thumbnail='thumbnail/heatmap_animation.gif', ipynb= '~notebook_demo/131', display_as='animations', order=4) ``` -------------------------------- ### Publish Notebook Example Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/interpolation-and-extrapolation-in-2d.md This code snippet is used to publish the current notebook as an example on the Plotly platform. It requires the `publisher` library and sets metadata for the online example, including title, description, and language. ```python from IPython.display import display, HTML display(HTML('')) display(HTML('')) ! pip install git+https://github.com/plotly/publisher.git --upgrade import publisher publisher.publish( 'python_Interpolation_and_Extrapolation_in_2D.ipynb', 'python/interpolation-and-extrapolation-in-2d/', 'Interpolation and Extrapolation in 2D | plotly', 'Learn how to interpolation and extrapolate data in two dimensions', title='Interpolation and Extrapolation in 2D in Python. | plotly', name='Interpolation and Extrapolation in 2D', language='python', page_type='example_index', has_thumbnail='false', display_as='mathematics', order=4, ipynb= '~notebook_demo/105') ``` -------------------------------- ### Install Kaleido using conda Source: https://github.com/plotly/plotly.py/blob/main/README.md Install Kaleido using conda for static image export. ```bash conda install -c conda-forge python-kaleido ``` -------------------------------- ### Install Notebook and Anywidget for Jupyter Notebook Source: https://github.com/plotly/plotly.py/blob/main/doc/python/getting-started.md Install necessary packages for Plotly support in classic Jupyter Notebook. ```bash pip install "notebook>=7.0" "anywidget>=0.9.13" ``` ```bash conda install "notebook>=7.0" "anywidget>=0.9.13" ``` -------------------------------- ### Publish Notebook Example Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/peak-integration.md Publishes a Jupyter Notebook as an example to the Plotly documentation site. Requires the `publisher` library and IPython display utilities. ```python from IPython.display import display, HTML display(HTML('')) display(HTML('')) ! pip install git+https://github.com/plotly/publisher.git --upgrade import publisher publisher.publish( 'python-Peak-Integration.ipynb', 'python/peak-integration/', 'Peak Integration | plotly', 'Learn how to integrate the area between peaks and bassline in Python.', title='Peak Integration in Python | plotly', name='Peak Integration', language='python', page_type='example_index', has_thumbnail='false', display_as='peak-analysis', order=4, ipynb= '~notebook_demo/121') ``` -------------------------------- ### Install and Publish Notebook Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/chord-diagram.md Installs the publisher package and publishes a Jupyter notebook as a Plotly chart. Ensure the notebook file and target directory exist. ```python from IPython.display import display, HTML display(HTML('')) display(HTML('')) ! pip install publisher --upgrade import publisher publisher.publish( 'chord.ipynb', 'python/chord-diagram/', 'Python Chord Diagram', 'How to make an interactive chord diagram in Python with Plotly and iGraph. ', title = 'Chord Diagram | Plotly', thumbnail='thumbnail/chord.jpg', language='python', has_thumbnail='true', display_as='scientific', order=24, ipynb= '~notebook_demo/225') ``` -------------------------------- ### Publish Plotly Example Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/1d-correlation.md This code snippet is used to publish the Plotly Python example to the Plotly website. It requires the 'publisher' library to be installed. ```python from IPython.display import display, HTML display(HTML('')) display(HTML('')) ! pip install git+https://github.com/plotly/publisher.git --upgrade import publisher publisher.publish( 'python-1D-Correlation.ipynb', 'python/1d-correlation/', '1D Correlation | plotly', 'Learn how to perform 1 dimensional correlation between two signals in Python.', title='1D Correlation in Python | plotly', name='1D Correlation', language='python', page_type='example_index', has_thumbnail='false', display_as='signal-analysis', order=5) ``` -------------------------------- ### Build Single Tutorial Page Source: https://github.com/plotly/plotly.py/blob/main/doc/README.md Command to build a single tutorial page's HTML output within the documentation directory. ```bash cd doc make build/html/2019-07-03-my-feature.html ``` -------------------------------- ### Configure Notebook Environment and Publish Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/amazon-redshift.md Initializes custom CSS for the notebook and uses the publisher module to register the tutorial. ```python from IPython.display import display, HTML display(HTML('')) display(HTML('')) ! pip install git+https://github.com/plotly/publisher.git --upgrade import publisher publisher.publish( 'redshift.ipynb', 'python/amazon-redshift/', 'Plot Data From Amazon Redshift', 'A tutorial showing how to plot Amazon AWS Redshift data with Plotly.', title = 'Plot Data from Amazon Redshift | plotly', has_thumbnail='false', redirect_from='ipython-notebooks/amazon-redshift/', language='python', page_type='example_index', display_as='databases', order=3, ipynb= '~notebook_demo/1') ``` -------------------------------- ### Build All Tutorials in Parallel Source: https://github.com/plotly/plotly.py/blob/main/doc/README.md Builds all tutorials in parallel using 8 jobs. The -k flag ensures the build continues even if some tutorials fail. ```bash make -kj8 ``` -------------------------------- ### Install and Configure Plotly Publisher Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/pdf-reports.md Install the publisher package and import necessary IPython display modules. This setup is required for publishing Plotly reports. ```python ! pip install publisher --upgrade from IPython.display import HTML, display display(HTML('')) display(HTML('')) ! pip install git+https://github.com/plotly/publisher.git --upgrade import publisher publisher.publish('pdf-reports.ipynb', 'python/pdf-reports/', 'PDF Reports' 'How to make PDF reports with Python and Plotly Graphs.', title = 'Python PDF Reports | plotly', name = 'PDF Reports', has_thumbnail='true', thumbnail='thumbnail/ipython_10_pdf_report.jpg', language='python', page_type='example_index', display_as='report_generation', order=1) ``` -------------------------------- ### Publish T-Test Notebook Example Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/t-test.md Publishes a Jupyter notebook example demonstrating T-Tests in Python to the Plotly platform. This snippet requires the 'publisher' library to be installed and configured. ```python from IPython.display import display, HTML display(HTML('')) display(HTML('')) ! pip install git+https://github.com/plotly/publisher.git --upgrade import publisher publisher.publish( 'python-T-Test.ipynb', 'python/t-test/', 'T-Test | plotly', 'Learn how to perform a one sample and two sample t-test using Python.', title='T-Test in Python. | plotly', name='T-Test', language='python', page_type='example_index', has_thumbnail='false', display_as='statistics', order=7, ipynb= '~notebook_demo/115') ``` -------------------------------- ### Configure Notebook Environment and Publish Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/numerical-differentiation.md Sets up notebook styling and publishes the notebook using the publisher utility. ```python from IPython.display import display, HTML display(HTML('')) display(HTML('')) ! pip install git+https://github.com/plotly/publisher.git --upgrade import publisher publisher.publish( 'python_Numerical_Differentiation.ipynb', 'python/numerical-differentiation/', 'Numerical Differentiation | plotly', 'Learn how to differentiate a sequence or list of values numerically', title='Numerical Differentiation in Python. | plotly', name='Numerical Differentiation', language='python', page_type='example_index', has_thumbnail='false', display_as='mathematics', order=6, ipynb= '~notebook_demo/102') ``` -------------------------------- ### Configure Spark Context Startup Script Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/apache-spark.md Startup script content to ensure the Spark Context is initialized when starting an IPython Notebook. ```py import os import sys spark_home = os.environ.get('SPARK_HOME', None) # check if it exists if not spark_home: raise ValueError('SPARK_HOME environment variable is not set') ``` -------------------------------- ### Tables in Dash Applications Source: https://github.com/plotly/plotly.py/blob/main/doc/python/table.md This snippet shows how to embed a Plotly table within a Dash application. Ensure Dash is installed (`pip install dash`) to run this example. ```python from IPython.display import IFrame snippet_url = 'https://python-docs-dash-snippets.herokuapp.com/python-docs-dash-snippets/' IFrame(snippet_url + 'table', width='100%', height=1200) ``` -------------------------------- ### Publish Notebook Example Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/normalization.md This snippet configures and publishes a Plotly notebook example. It requires the 'publisher' library to be installed and the notebook file to exist. It sets metadata for the published page. ```python from IPython.display import display, HTML display(HTML('')) display(HTML('')) ! pip install git+https://github.com/plotly/publisher.git --upgrade import publisher publisher.publish( 'python_Normalization.ipynb', 'python/normalization/', 'Normalization | plotly', 'Learn how to normalize data by fitting to intervals on the real line and dividing by a constant', title='Normalization in Python. | plotly', name='Normalization', language='python', page_type='example_index', has_thumbnail='false', display_as='mathematics', order=2, ipynb= '~notebook_demo/103') ``` -------------------------------- ### Build a Single Tutorial Source: https://github.com/plotly/plotly.py/blob/main/doc/README.md Builds a specific tutorial page, useful for development. The filename follows a YYYY-MM-DD-.html pattern. ```bash make build/html/2019-07-03-bar-charts.html ``` -------------------------------- ### Control Hover Mode with Dash Source: https://github.com/plotly/plotly.py/blob/main/doc/python/hover-text-and-formatting.md This snippet demonstrates controlling hover modes within a Dash application. Ensure Dash is installed (`pip install dash`) to run this example. ```python from IPython.display import IFrame snippet_url = 'https://python-docs-dash-snippets.herokuapp.com/python-docs-dash-snippets/' IFrame(snippet_url + 'hover-text-and-formatting', width='100%', height=1200) ``` -------------------------------- ### Dash Colorscales Example Source: https://github.com/plotly/plotly.py/blob/main/doc/python/colorscales.md This snippet demonstrates how to integrate Plotly figures with continuous color scales within a Dash application. Ensure you have Dash installed (`pip install dash`). ```python from IPython.display import IFrame snippet_url = 'https://python-docs-dash-snippets.herokuapp.com/python-docs-dash-snippets/' IFrame(snippet_url + 'colorscales', width='100%', height=1200) ``` -------------------------------- ### Start IPython with Spark Profile Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/apache-spark.md Command to launch the notebook server using the configured pyspark profile. ```bash ipython notebook --profile=pyspark ``` -------------------------------- ### Build All Tutorials Source: https://github.com/plotly/plotly.py/blob/main/doc/README.md Builds all Markdown files in the python/ directory into Jupyter notebooks, then executes them and converts them to HTML. This process is used for the continuous integration build. ```bash cd doc source .venv/bin/activate make ``` -------------------------------- ### Subplots in Dash Application Source: https://github.com/plotly/plotly.py/blob/main/doc/python/subplots.md Example of integrating Plotly subplots within a Dash application. Requires 'dash' to be installed. ```python from IPython.display import IFrame snippet_url = 'https://python-docs-dash-snippets.herokuapp.com/python-docs-dash-snippets/' IFrame(snippet_url + 'subplots', width='100%', height=1200) ``` -------------------------------- ### Publish Baseline Subtraction Example Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/baseline-subtraction.md This script configures and publishes a Plotly notebook example for baseline subtraction in Python. It installs the necessary publisher package and uses it to upload the notebook to Plotly's platform with specified metadata. ```python from IPython.display import display, HTML display(HTML('')) display(HTML('')) ! pip install git+https://github.com/plotly/publisher.git --upgrade import publisher publisher.publish( 'python-Baseline-Subtraction.ipynb', 'python/baseline-subtraction/', 'Baseline Subtraction | plotly', 'Learn how to subtract baseline estimates from data in Python.', title='Baseline Subtraction in Python | plotly', name='Baseline Subtraction', language='python', page_type='example_index', has_thumbnail='false', display_as='peak-analysis', order=2, ipynb= '~notebook_demo/118') ``` -------------------------------- ### Setting Up Plotting Utilities Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/cmocean-colorscales.md Loads example data and defines a function to generate a multi-panel heatmap figure. ```python # Plotting the colorscale. example_dir = os.path.join(os.path.dirname('__file__'), "examples") hist2d = np.loadtxt(os.path.join(example_dir, "hist2d.txt")) st_helens = np.loadtxt(os.path.join(example_dir, "st-helens_before-modified.txt.gz")).T dx = dy = 0.05 y, x = np.mgrid[-5 : 5 + dy : dy, -5 : 10 + dx : dx] z = np.sin(x)**10 + np.cos(10 + y*x) + np.cos(x) + 0.2*y + 0.1*x elem_len = [len(hist2d), len(st_helens), len(z)] max_len = max(elem_len) def colorscale_plot(colorscale, title): trace1 = go.Heatmap(z=hist2d, colorscale=colorscale, showscale=False) trace2 = go.Heatmap(z=st_helens, colorscale=colorscale, y0=-5, x0=-5) trace3 = go.Heatmap(z=z,colorscale=colorscale, showscale=False) fig = tools.make_subplots(rows=1, cols=3, print_grid=False) fig.append_trace(trace1, 1, 1) fig.append_trace(trace2, 1, 2) fig.append_trace(trace3, 1, 3) fig['layout'].update(title=title) fig['layout']['xaxis2'].update(range=[0, 450]) fig['layout']['yaxis2'].update(range=[0, 270]) return fig ``` -------------------------------- ### Tutorial YAML Frontmatter Example Source: https://github.com/plotly/plotly.py/blob/main/doc/README.md An example of the YAML frontmatter used in tutorial files, including Jupyter notebook metadata and Plotly-specific configuration for navigation, SEO, and categorization. ```yaml --- jupyter: jupytext: notebook_metadata_filter: all text_representation: extension: .md format_name: markdown format_version: '1.3' jupytext_version: 1.17.3 kernelspec: display_name: Python 3 (ipykernel) language: python name: python3 language_info: codemirror_mode: name: ipython version: 3 file_extension: .py mimetype: text/x-python name: python nbconvert_exporter: python pygments_lexer: ipython3 version: 3.9.0 plotly: description: Short description for SEO and page previews. display_as: basic # Category: basic, statistical, scientific, maps, 3d, etc. language: python layout: base name: Page Title # Displayed in the navigation sidebar order: 3 # Position within the display_as category page_type: example_index permalink: python/my-page/ # URL path on the documentation site thumbnail: thumbnail/my-page.jpg --- ``` -------------------------------- ### Publish Ribbon Plot Example Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/ribbon-plots.md This snippet demonstrates how to publish a Plotly chart, specifically a ribbon plot example, to the Plotly platform. It requires the `publisher` library and IPython display utilities. Ensure the `publisher` library is installed and upgraded. ```python from IPython.display import display, HTML display(HTML('')) display(HTML('')) ! pip install git+https://github.com/plotly/publisher.git --upgrade import publisher publisher.publish( 'ribbon.ipynb', 'python/ribbon-plots/', 'Python Ribbon Plots | plotly', 'How to make ribbon plots in Python. ', title = 'Python Ribbon Plots | plotly', name = 'Ribbon Plots', has_thumbnail='true', thumbnail='thumbnail/ribbon-plot.jpg', language='python', page_type='example_index', display_as='3d_charts', order=4, ipynb= '~notebook_demo/64') ``` -------------------------------- ### Publish Logos Notebook | Python Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/logos.md Use the `publisher` library to publish a notebook containing logo examples. Ensure the library is installed and upgraded. ```python from IPython.display import display, HTML display(HTML('')) display(HTML('')) ! pip install git+https://github.com/plotly/publisher.git --upgrade import publisher publisher.publish( 'logos.ipynb', 'python/logos/', 'Add Logos to Charts', 'How to add images as logos to Plotly charts.', title = 'Add Logos to Charts | plotly', name = 'Logos', has_thumbnail='false', thumbnail='thumbnail/your-tutorial-chart.jpg', language='python', page_type='example_index', display_as='style_opt', order=6, ipynb= '~notebook_demo/92') ``` -------------------------------- ### Configure Notebook Environment and Publish Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/webgl-text-and-annotations.md Sets up custom CSS for Jupyter notebooks and uses the publisher module to deploy the notebook example. ```python from IPython.display import display, HTML display(HTML('')) display(HTML('')) ! pip install git+https://github.com/plotly/publisher.git --upgrade import publisher publisher.publish( 'webgl-text-and-annotations.ipynb', 'python/webgl-text-and-annotations/', 'WebGL Text and Annotations', 'How to add webGL based text labels and annotations to plots in python', title = 'WebGL Text and Annotations | plotly', name = 'WebGL Text and Annotations', has_thumbnail='false', thumbnail='thumbnail/webgl-text-and-annotations.jpg', language='python', page_type='example_index', display_as='style_opt', order=2, ipynb= '~notebook_demo/219', uses_plotly_offline=False) ``` -------------------------------- ### Configure and Publish 3D Network Graph Notebook Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/3d-network-graph.md Initializes the environment with required CSS and uses the publisher module to register the notebook. ```python from IPython.display import display, HTML display(HTML('')) display(HTML('')) ! pip install git+https://github.com/plotly/publisher.git --upgrade import publisher publisher.publish( 'Les-miserables-network.ipynb', 'python/3d-network-graph/', 'Python 3D Network Graphs', 'How to make 3D Network Graphs in Python. ', title = '3D Network Graphs in Python | plotly', name = '3D Network Graphs', has_thumbnail='true', thumbnail='thumbnail/3dnetwork.jpg', language='python', page_type='example_index', display_as='3d_charts', order=13, ipynb= '~notebook_demo/226') ``` -------------------------------- ### Create a Simple Play Button Source: https://github.com/plotly/plotly.py/blob/main/doc/python/animations.md Demonstrates a basic animation setup where a button triggers the playback of defined frames. ```python import plotly.graph_objects as go fig = go.Figure( data=[go.Scatter(x=[0, 1], y=[0, 1])], layout=go.Layout( xaxis=dict(range=[0, 5], autorange=False), yaxis=dict(range=[0, 5], autorange=False), title=dict(text="Start Title"), updatemenus=[dict( type="buttons", buttons=[dict(label="Play", method="animate", args=[None])])] ), frames=[go.Frame(data=[go.Scatter(x=[1, 2], y=[1, 2])]), go.Frame(data=[go.Scatter(x=[1, 4], y=[1, 4])]), go.Frame(data=[go.Scatter(x=[3, 4], y=[3, 4])], layout=go.Layout(title_text="End Title"))] ) fig.show() ``` -------------------------------- ### Get ideogram arc end coordinates Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/filled-chord-diagram.md Generates a list of start and end angular coordinates for each ideogram arc. The function accounts for the gap between arcs. ```python def get_ideogram_ends(ideogram_len, gap): ideo_ends=[] left=0 for k in range(len(ideogram_len)): right=left+ideogram_len[k] ideo_ends.append([left, right]) left=right+gap return ideo_ends ideo_ends=get_ideogram_ends(ideogram_length, gap) ideo_ends ``` -------------------------------- ### Create Subplots with make_subplots Source: https://github.com/plotly/plotly.py/blob/main/doc/python/subplots.md The `plotly.subplots.make_subplots` function is the standard way to create figures with multiple subplots. This example shows an equivalent setup to the direct `set_subplots` method. ```python from plotly.subplots import make_subplots fig = make_subplots(2, 3, horizontal_spacing=0.1) ``` -------------------------------- ### Publishing and Styling Notebooks Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/insets.md Configures notebook CSS and uses the publisher utility to deploy the example notebook. ```python from IPython.display import display, HTML display(HTML('')) display(HTML('')) !pip install git+https://github.com/plotly/publisher.git --upgrade import publisher publisher.publish( 'inset.ipynb', 'python/insets/', 'Inset Plots | plotly', 'How to make an inset graph in python.', title = 'Inset Plots | plotly', name = 'Inset Plots', has_thumbnail='true', thumbnail='thumbnail/insets.jpg', language='python', page_type='example_index', display_as='multiple_axes', order=3) ``` -------------------------------- ### 2D and 3D Projections with UMAP Source: https://github.com/plotly/plotly.py/blob/main/doc/python/ml-tsne-umap-projections.md Use UMAP for 2D and 3D dimensionality reduction. This example uses the iris dataset and Plotly Express for visualization. Ensure UMAP and Plotly are installed. ```python from umap import UMAP import plotly.express as px df = px.data.iris() features = df.loc[:, :'petal_width'] umap_2d = UMAP(n_components=2, init='random', random_state=0) umap_3d = UMAP(n_components=3, init='random', random_state=0) proj_2d = umap_2d.fit_transform(features) proj_3d = umap_3d.fit_transform(features) fig_2d = px.scatter( proj_2d, x=0, y=1, color=df.species, labels={'color': 'species'} ) fig_3d = px.scatter_3d( proj_3d, x=0, y=1, z=2, color=df.species, labels={'color': 'species'} ) fig_3d.update_traces(marker_size=5) fig_2d.show() fig_3d.show() ``` -------------------------------- ### Create a Basic Table Source: https://github.com/plotly/plotly.py/blob/main/doc/python/table.md Use `go.Table` to create a simple table with headers and cell values. Data is provided in a column-major format. ```python import plotly.graph_objects as go fig = go.Figure(data=[go.Table(header=dict(values=['A Scores', 'B Scores']), cells=dict(values=[[100, 90, 80, 90], [95, 85, 75, 95]])) ]) fig.show() ``` -------------------------------- ### Display Sankey Diagram in a Dash Application Source: https://github.com/plotly/plotly.py/blob/main/doc/python/sankey-diagram.md Integrates a Sankey diagram into a Dash application. Requires installation of the 'dash' library. The provided code snippet is an iframe embedding a live example. ```python from IPython.display import IFrame snippet_url = 'https://python-docs-dash-snippets.herokuapp.com/python-docs-dash-snippets/' IFrame(snippet_url + 'sankey-diagram', width='100%', height=1200) ``` -------------------------------- ### Configure Notebook Environment and Publish Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/google_big_query.md Set up notebook styling and publish the notebook using the Plotly publisher utility. ```python from IPython.display import display, HTML display(HTML('')) display(HTML('')) ! pip install git+https://github.com/plotly/publisher.git --upgrade import publisher publisher.publish( 'BigQuery-Plotly.ipynb', 'python/google_big_query/', 'Google Big-Query', 'How to make your-tutorial-chart plots in Python with Plotly.', title = 'Google Big Query | plotly', has_thumbnail='true', thumbnail='thumbnail/bigquery2.jpg', language='python', page_type='example_index', display_as='databases', order=7) ``` -------------------------------- ### Create Density Heatmap with Mapbox using Plotly Express Source: https://github.com/plotly/plotly.py/blob/main/doc/python/density-heatmaps.md This example demonstrates using `px.density_mapbox` for creating density heatmaps with Mapbox tiles. Ensure you have the necessary Mapbox setup if using custom styles. ```python import pandas as pd df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv') import plotly.express as px fig = px.density_mapbox(df, lat='Latitude', lon='Longitude', z='Magnitude', radius=10, center=dict(lat=0, lon=180), zoom=0, mapbox_style="open-street-map") fig.show() ``` -------------------------------- ### Displaying Period Data with Different Alignments Source: https://github.com/plotly/plotly.py/blob/main/doc/python/time-series.md Configure traces to display marks at the start, middle, or end of a period using `xperiod` and `xperiodalignment`. This example shows raw data alongside monthly-aligned scatter and bar traces. ```python import plotly.graph_objects as go import pandas as pd df = pd.DataFrame(dict( date=["2020-01-10", "2020-02-10", "2020-03-10", "2020-04-10", "2020-05-10", "2020-06-10"], value=[1,2,3,1,2,3] )) fig = go.Figure() fig.add_trace(go.Scatter( name="Raw Data", mode="markers+lines", x=df["date"], y=df["value"], marker_symbol="star" )) fig.add_trace(go.Scatter( name="Start-aligned", mode="markers+lines", x=df["date"], y=df["value"], xperiod="M1", xperiodalignment="start" )) fig.add_trace(go.Scatter( name="Middle-aligned", mode="markers+lines", x=df["date"], y=df["value"], xperiod="M1", xperiodalignment="middle" )) fig.add_trace(go.Scatter( name="End-aligned", mode="markers+lines", x=df["date"], y=df["value"], xperiod="M1", xperiodalignment="end" )) fig.add_trace(go.Bar( name="Middle-aligned", x=df["date"], y=df["value"], xperiod="M1", xperiodalignment="middle" )) fig.update_xaxes(showgrid=True, ticklabelmode="period") fig.show() ``` -------------------------------- ### Create Large Scatter Plot with WebGL using Plotly Express Source: https://github.com/plotly/plotly.py/blob/main/doc/python/performance.md This example demonstrates creating a scatter plot with 100,000 points using Plotly Express, explicitly enabling WebGL rendering for performance. Ensure necessary libraries like pandas and numpy are installed. ```python import plotly.express as px import pandas as pd import numpy as np np.random.seed(1) N = 100000 df = pd.DataFrame(dict(x=np.random.randn(N), y=np.random.randn(N))) fig = px.scatter(df, x="x", y="y", render_mode='webgl') fig.update_traces(marker_line=dict(width=1, color='DarkSlateGray')) fig.show() ``` -------------------------------- ### Publishing notebook examples Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/tesla-supercharging-stations.md Configures notebook display settings and publishes the notebook to the Plotly platform. ```python from IPython.display import display, HTML display(HTML('')) display(HTML('')) #! pip install git+https://github.com/plotly/publisher.git --upgrade import publisher publisher.publish( 'tesla-supercharging-stations.ipynb', 'python/tesla-supercharging-stations/', 'Python Tesla Supercharging Stations | Examples | Plotly', 'How to plot car-travel routes between USA and Canada Telsa Supercharging Stations in Python.', title = 'Tesla Supercharging Stations | Plotly', name = 'Tesla Supercharging Stations', has_thumbnail='true', thumbnail='thumbnail/tesla-stations.jpg', language='python', display_as='maps', order=10, ipynb= '~notebook_demo/124') ``` -------------------------------- ### Initialize a Dashboard Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/create-online-dashboard-legacy.md Create a new dashboard object and generate a preview of its layout. ```python import plotly.dashboard_objs as dashboard import IPython.display from IPython.display import Image my_dboard = dashboard.Dashboard() my_dboard.get_preview() ``` -------------------------------- ### Install Required Packages Source: https://github.com/plotly/plotly.py/blob/main/doc/python/county-choropleth.md Install the necessary packages for the figure factory to run. If using Anaconda, use 'conda install' instead of 'pip'. ```python !pip install plotly-geo==1.0.0 !pip install geopandas==0.8.1 !pip install pyshp==2.1.2 !pip install shapely==1.7.1 ``` ```python conda install plotly conda install geopandas ``` -------------------------------- ### Install igraph dependency Source: https://github.com/plotly/plotly.py/blob/main/doc/python/tree-plots.md Install the required igraph package via pip. ```python !pip install igraph ``` -------------------------------- ### Authenticate with Salesforce Source: https://github.com/plotly/plotly.py/blob/main/doc/unconverted/python/salesforce.md Initialize a Salesforce connection using credentials stored in a local file. ```python with open('salesforce_login.txt') as f: username, password, token = [x.strip("\n") for x in f.readlines()] sf = Salesforce(username=username, password=password, security_token=token) ```