diff --git a/notebooks/data-api.md b/notebooks/data-api.md index 472361136..ef17bf19a 100644 --- a/notebooks/data-api.md +++ b/notebooks/data-api.md @@ -6,12 +6,23 @@ jupyter: extension: .md format_name: markdown format_version: '1.1' - jupytext_version: 1.1.1 + jupytext_version: 1.1.7 kernelspec: - display_name: Python 2 + display_name: Python 3 language: python - name: python2 + 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.6.5 plotly: + v4upgrade: true description: How to upload data to Plotly from Python with the Plotly Grid API. display_as: file_settings has_thumbnail: true @@ -25,13 +36,6 @@ jupyter: title: Plotly Data API --- -#### New to Plotly? -Plotly's Python library is free and open source! [Get started](https://plot.ly/python/getting-started/) by downloading the client and [reading the primer](https://plot.ly/python/getting-started/). -
You can set up Plotly to work in [online](https://plot.ly/python/getting-started/#initialization-for-online-plotting) or [offline](https://plot.ly/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plot.ly/python/getting-started/#start-plotting-online). -
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started! - - - #### Creating a Plotly Grid You can instantiate a grid with data by either uploading tabular data to Plotly or by creating a Plotly `grid` using the API. To upload the grid we will use `plotly.plotly.grid_ops.upload()`. It takes the following arguments: - `grid` (Grid Object): the actual grid object that you are uploading. @@ -42,15 +46,15 @@ You can instantiate a grid with data by either uploading tabular data to Plotly You can run `help(py.grid_ops.upload)` for a more detailed description of these and all the arguments. ```python -import plotly -import plotly.plotly as py -import plotly.tools as tls -import plotly.graph_objs as go -from plotly.grid_objs import Column, Grid +import chart_studio +import chart_studio.plotly as py +import chart_studio.tools as tls +import plotly.graph_objects as go +from chart_studio.grid_objs import Column, Grid from datetime import datetime as dt import numpy as np -from IPython.display import Image +from IPython.display import IFrame column_1 = Column(['a', 'b', 'c'], 'column 1') column_2 = Column([1, 2, 3], 'column 2') # Tabular data can be numbers, strings, or dates @@ -66,7 +70,7 @@ print(url) You can view your newly created grid at the `url`: ```python -Image('view_grid_url.png') +IFrame(src= url.rstrip('/') + ".embed", width="100%",height="200px", frameBorder="0") ``` You are also able to view the grid in your list of files inside your [organize folder](https://plot.ly/organize). @@ -76,7 +80,7 @@ You are also able to view the grid in your list of files inside your [organize f Along with uploading a grid, you can upload a Dataframe as well as convert it to raw data as a grid: ```python -import plotly.plotly as py +import chart_studio.plotly as py import plotly.figure_factory as ff import pandas as pd @@ -87,12 +91,6 @@ table = ff.create_table(df_head) py.iplot(table, filename='dataframe_ex_preview') ``` -```python -grid = Grid([Column(df[column_name], column_name) for column_name in df.columns]) -url = py.grid_ops.upload(grid, filename='dataframe_ex_'+str(dt.now()), world_readable=True, auto_open=True) -print(url) -``` - #### Making Graphs from Grids Plotly graphs are usually described with data embedded in them. For example, here we place `x` and `y` data directly into our `Histogram2dContour` object: @@ -124,7 +122,7 @@ print(url) ``` ```python -Image('rand_int_histogram_view.png') +IFrame(src= url.rstrip('/') + ".embed", width="100%",height="200px", frameBorder="0") ``` #### Make Graph from Raw Data @@ -163,32 +161,12 @@ grid_url = py.grid_ops.upload(grid, filename='grid_with_metadata_'+str(dt.now()) print(url) ``` -```python -Image('metadata_view.png') -``` - #### Reference ```python help(py.grid_ops) ``` -```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( - 'grid-api.ipynb', 'python/data-api/', 'Upload Data to Plotly from Python', - 'How to upload data to Plotly from Python with the Plotly Grid API.', - title = 'Plotly Data API', name = 'Plots from Grids', order = 5, - language='python', has_thumbnail='true', thumbnail='thumbnail/table.jpg', display_as='file_settings' -) -``` - ```python ``` diff --git a/notebooks/delete-plots.md b/notebooks/delete-plots.md index f88675afb..c26b3e2d7 100644 --- a/notebooks/delete-plots.md +++ b/notebooks/delete-plots.md @@ -6,12 +6,23 @@ jupyter: extension: .md format_name: markdown format_version: '1.1' - jupytext_version: 1.1.1 + jupytext_version: 1.1.7 kernelspec: - display_name: Python 2 + display_name: Python 3 language: python - name: python2 + 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.6.5 plotly: + v4upgrade: true description: How to delete plotly graphs in python. display_as: file_settings has_thumbnail: true @@ -25,20 +36,14 @@ jupyter: thumbnail: thumbnail/delete.jpg --- -#### New to Plotly? -Plotly's Python library is free and open source! [Get started](https://plot.ly/python/getting-started/) by downloading the client and [reading the primer](https://plot.ly/python/getting-started/). -
You can set up Plotly to work in [online](https://plot.ly/python/getting-started/#initialization-for-online-plotting) or [offline](https://plot.ly/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plot.ly/python/getting-started/#start-plotting-online). -
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started! - - #### Imports and Credentials In additional to importing python's `requests` and `json` packages, this tutorial also uses [Plotly's REST API](https://api.plot.ly/v2/) First define YOUR [username and api key](https://plot.ly/settings/api) and create `auth` and `headers` to use with `requests` ```python -import plotly -import plotly.plotly as py +import chart_studio +import chart_studio.plotly as py import json import requests @@ -50,7 +55,7 @@ api_key = 'k0yy0ztssk' # Replace with YOUR API KEY auth = HTTPBasicAuth(username, api_key) headers = {'Plotly-Client-Platform': 'python'} -plotly.tools.set_credentials_file(username=username, api_key=api_key) +chart_studio.tools.set_credentials_file(username=username, api_key=api_key) ``` #### [Trash](https://api.plot.ly/v2/files/#trash) and [Restore](https://api.plot.ly/v2/files/#restore) @@ -68,7 +73,7 @@ url Include the file id in your request.
The file id is your `username:plot_id#` ```python -fid = username+':18' +fid = username+':604' fid ``` @@ -98,7 +103,7 @@ url ``` ```python -fid_permanent_delete = username+':79' +fid_permanent_delete = username+':652' fid_permanent_delete ``` @@ -154,22 +159,6 @@ permanently_delete_files(username, filetype_to_delete='plot') permanently_delete_files(username, filetype_to_delete='grid') ``` -```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( - 'delete.ipynb', 'python/delete-plots/', 'Deleting Plots with the Python API', - 'How to delete plotly graphs in python.', - name = 'Deleting Plots', language='python', - has_thumbnail='true', thumbnail= 'thumbnail/delete.jpg', - display_as='file_settings', ipynb= '~notebook_demo/98', order=9) -``` - ```python ``` diff --git a/notebooks/embedding-charts.md b/notebooks/embedding-charts.md new file mode 100644 index 000000000..b785d7dab --- /dev/null +++ b/notebooks/embedding-charts.md @@ -0,0 +1,49 @@ +--- +jupyter: + jupytext: + notebook_metadata_filter: all + text_representation: + extension: .md + format_name: markdown + format_version: '1.1' + jupytext_version: 1.1.7 + kernelspec: + display_name: Python 3 + 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.6.5 + plotly: + v4upgrade: true + title: Python Embedding Graphs in HTML | Examples | Plotly + name: Embedding Graphs in HTML + permalink: python/embedding-plotly-graphs-in-HTML/ + description: How to embed plotly graphs with an iframe in HTML. + layout: user-guide + language: python + has_thumbnail: true + thumbnail: thumbnail/embed.jpg + display_as: chart_studio + order: 6 +--- + +Plotly graphs can be embedded in any HTML page. This includes [IPython notebooks](https://plot.ly/ipython-notebooks/), [Wordpress sites](https://wordpress.org/plugins/wp-plotly), dashboards, blogs, and more. + +For more on embedding Plotly graphs in HTML documents, [see our tutorial](https://plot.ly/how-to-embed-plotly-graphs-in-websites). + +From Python, you can generate the HTML code to embed Plotly graphs with the `plotly.tools.get_embed` function. + + +```python +import chart_studio.tools as tls + +tls.get_embed('https://plot.ly/~chris/1638') +``` diff --git a/notebooks/file-options.md b/notebooks/file-options.md deleted file mode 100644 index b62429f01..000000000 --- a/notebooks/file-options.md +++ /dev/null @@ -1,180 +0,0 @@ ---- -jupyter: - jupytext: - notebook_metadata_filter: all - text_representation: - extension: .md - format_name: markdown - format_version: '1.1' - jupytext_version: 1.1.1 - kernelspec: - display_name: Python 3 - language: python - name: python3 - plotly: - description: How to update your graphs in Python with the fileopt parameter. - display_as: file_settings - has_thumbnail: true - language: python - layout: user-guide - name: Updating Plotly Graphs - order: 3 - page_type: example_index - permalink: python/file-options/ - thumbnail: thumbnail/horizontal-bar.jpg - title: Python Filenames Options | Plotly ---- - -#### New to Plotly? -Plotly's Python library is free and open source! [Get started](https://plot.ly/python/getting-started/) by downloading the client and [reading the primer](https://plot.ly/python/getting-started/). -
You can set up Plotly to work in [online](https://plot.ly/python/getting-started/#initialization-for-online-plotting) or [offline](https://plot.ly/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plot.ly/python/getting-started/#start-plotting-online). -
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started! - - -#### Version Check -Plotly's python package is updated frequently. Run `pip install plotly --upgrade` to use the latest version. - -```python -import plotly -plotly.__version__ -``` - -#### Overwriting existing graphs and updating a graph at its unique URL - - -By default, Plotly will overwrite files made with the same filename. For example, if a graph named 'my plot' already exists in your account, then it will be overwritten with this new version and the URL of the graph will persist. - -```python -import plotly.plotly as py -import plotly.graph_objs as go - -data = [ - go.Scatter( - x=[1, 2], - y=[3, 4] - ) -] - -plot_url = py.plot(data, filename='my plot') -``` - -#### Saving to a folder - - -Filenames that contain `"/"` be treated as a Plotly directory and will be saved to your Plotly account in a folder tree. For example, to save your graphs to the folder `my-graphs` use the `filename = "my-graphs/my plot"` (if it doesn't already exist it will be created) - -```python -import plotly.plotly as py -import plotly.graph_objs as go - -data = [ - go.Scatter( - x=[1, 2], - y=[3, 4] - ) -] - -plot_url = py.plot(data, filename='my-graphs/my plot') -``` - -#### Creating new files - - -With `fileopt='new'`, Plotly will always create a new file. If a file with the same name already exists, then Plotly will append a '(1)' to the end of the filename, e.g. `new plot (1)` and create a unique URL. - -```python -import plotly.plotly as py -import plotly.graph_objs as go - -data = [ - go.Scatter( - x=[1, 2], - y=[3, 4] - ) -] - -plot_url = py.plot(data, filename='new plot', fileopt='new') -``` - -#### Extending traces in an existing graph - - -To extend existing traces with your new data, use `fileopt='extend'`. - -```python -import plotly.plotly as py -import plotly.graph_objs as go - -trace0 = go.Scatter( - x=[1, 2], - y=[1, 2] -) - -trace1 = go.Scatter( - x=[1, 2], - y=[2, 3] -) - -trace2 = go.Scatter( - x=[1, 2], - y=[3, 4] -) - -data = [trace0, trace1, trace2] - -# Take 1: if there is no data in the plot, 'extend' will create new traces. -plot_url = py.plot(data, filename='extend plot', fileopt='extend') -``` - -Then, extend the traces with more data. - -```python -import plotly.plotly as py -import plotly.graph_objs as go - -trace0 = go.Scatter( - x=[3, 4], - y=[2, 1] -) - -trace1 = go.Scatter( - x=[3, 4], - y=[3, 2] -) - -trace2 = go.Scatter( - x=[3, 4], - y=[4, 3] -) - -data = [trace0, trace1, trace2] - -# Take 2: extend the traces on the plot with the data in the order supplied. -py.iplot(data, filename='extend plot', fileopt='extend') -``` - -```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( - 'fileopts.ipynb', 'python/file-options/', 'Updating Plotly Graphs', - 'How to update your graphs in Python with the fileopt parameter.', - title = 'Python Filenames Options | Plotly', - has_thumbnail='true', - thumbnail='thumbnail/horizontal-bar.jpg', - language='python', - page_type='example_index', - display_as='file_settings', - order=3, - #ipynb='~notebook_demo/1' -) -``` - -```python - -``` diff --git a/notebooks/get-requests.md b/notebooks/get-requests.md new file mode 100644 index 000000000..2e1906b09 --- /dev/null +++ b/notebooks/get-requests.md @@ -0,0 +1,95 @@ +--- +jupyter: + jupytext: + notebook_metadata_filter: all + text_representation: + extension: .md + format_name: markdown + format_version: '1.1' + jupytext_version: 1.1.7 + kernelspec: + display_name: Python 3 + 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.6.5 + plotly: + v4upgrade: true + title: Python Get Requests | Examples | Plotly + name: Get Requests + permalink: python/get-requests/ + description: How to download plotly users's public graphs and data with python. + layout: user-guide + thumbnail: thumbnail/get-requests.jpg + language: python + has_thumbnail: true + thumbnail: thumbnail/spectral.jpg + display_as: chart_studio + order: 8 +--- + +#### Get and Change a Public Figure + +```python +import chart_studio.plotly as py +# Learn about API authentication here: https://plot.ly/python/getting-started +# Find your api_key here: https://plot.ly/settings/api + +fig = py.get_figure("https://plot.ly/~PlotBot/5") + +fig['layout']['title'] = "Never forget that title!" + +py.iplot(fig, filename="python-change_plot") +``` + +#### Get Data and Change Plot + +```python +import chart_studio.plotly as py +import plotly.graph_objects as go +# Learn about API authentication here: https://plot.ly/python/getting-started +# Find your api_key here: https://plot.ly/settings/api + +data = py.get_figure("https://plot.ly/~PythonPlotBot/3483").data +distance = [d['y'][0] for d in data] # check out the data for yourself! + +fig = go.Figure() +fig.add_histogram(y=distance, name="flyby distance", histnorm='probability') +xaxis = dict(title="Probability for Flyby at this Distance") +yaxis = dict(title="Distance from Earth (Earth Radii)") +fig.update_layout(title="data source: https://plot.ly/~AlexHP/68", xaxis=xaxis, yaxis=yaxis) + +plot_url = py.plot(fig, filename="python-get-data") +``` + +#### Get and Replot a Public Figure with URL + +```python +import chart_studio.plotly as py +# Learn about API authentication here: https://plot.ly/python/getting-started +# Find your api_key here: https://plot.ly/settings/api + +fig = py.get_figure("https://plot.ly/~PlotBot/5") + +plot_url = py.plot(fig, filename="python-replot1") +``` + +#### Get and Replot a Public Figure with ID + +```python +import chart_studio.plotly as py +# Learn about API authentication here: https://plot.ly/python/getting-started +# Find your api_key here: https://plot.ly/settings/api + +fig = py.get_figure("PlotBot", 5) + +plot_url = py.plot(fig, filename="python-replot2") +``` diff --git a/notebooks/getting-started-with-chart-studio.md b/notebooks/getting-started-with-chart-studio.md new file mode 100644 index 000000000..e17108a9e --- /dev/null +++ b/notebooks/getting-started-with-chart-studio.md @@ -0,0 +1,302 @@ +--- +jupyter: + jupytext: + notebook_metadata_filter: all + text_representation: + extension: .md + format_name: markdown + format_version: '1.1' + jupytext_version: 1.1.7 + kernelspec: + display_name: Python 3 + 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.6.5 + plotly: + description: Installation and Initialization Steps for Using Chart Studio in Python. + display_as: chart_studio + has_thumbnail: true + ipynb: ~notebook_demo/123/installation + language: python + layout: user-guide + name: Getting Started with Plotly for Python + order: 0.1 + page_type: example_index + permalink: python/getting-started-with-chart-studio/ + thumbnail: thumbnail/bubble.jpg + title: Getting Started with Chart Studio for Python | plotly + v4upgrade: true +--- + +### Installation + + +To install Chart Studio's python package, use the package manager **pip** inside your terminal.
+If you don't have **pip** installed on your machine, [click here](https://pip.pypa.io/en/latest/installing.html) for pip's installation instructions. +
+
+`$ pip install chart_studio` +
or +
`$ sudo pip install chart_studio` +
+
+Plotly's Python package is installed alongside the Chart Studio package and it is [updated frequently](https://github.com/plotly/plotly.py/blob/master/CHANGELOG.md)! To upgrade, run: +
+
+`$ pip install plotly --upgrade` + + +### Initialization for Online Plotting +Chart Studio provides a web-service for hosting graphs! Create a [free account](https://plot.ly/api_signup) to get started. Graphs are saved inside your online Chart Studio account and you control the privacy. Public hosting is free, for private hosting, check out our [paid plans](https://plot.ly/products/cloud/). +
+
+After installing the Chart Studio package, you're ready to fire up python: +
+
+`$ python` +
+
+and set your credentials: + +```python +import chart_studio +chart_studio.tools.set_credentials_file(username='DemoAccount', api_key='lr1c37zw81') +``` + + +You'll need to replace **'DemoAccount'** and **'lr1c37zw81'** with *your* Plotly username and [API key](https://plot.ly/settings/api).
+Find your API key [here](https://plot.ly/settings/api). +
+
+The initialization step places a special **.plotly/.credentials** file in your home directory. Your **~/.plotly/.credentials** file should look something like this: +
+``` +{ + "username": "DemoAccount", + "stream_ids": ["ylosqsyet5", "h2ct8btk1s", "oxz4fm883b"], + "api_key": "lr1c37zw81" +} +``` + + +### Online Plot Privacy + +Plot can be set to three different type of privacies: public, private or secret. +- **public**: Anyone can view this graph. It will appear in your profile and can appear in search engines. You do not need to be logged in to Chart Studio to view this chart. +- **private**: Only you can view this plot. It will not appear in the Plotly feed, your profile, or search engines. You must be logged in to Plotly to view this graph. You can privately share this graph with other Chart Studio users in your online Chart Studio account and they will need to be logged in to view this plot. +- **secret**: Anyone with this secret link can view this chart. It will not appear in the Chart Studio feed, your profile, or search engines. If it is embedded inside a webpage or an IPython notebook, anybody who is viewing that page will be able to view the graph. You do not need to be logged in to view this plot. + +By default all plots are set to **public**. Users with free account have the permission to keep one private plot. If you need to save private plots, [upgrade to a pro account](https://plot.ly/plans). If you're a [Personal or Professional user](https://plot.ly/settings/subscription/?modal=true&utm_source=api-docs&utm_medium=support-oss) and would like the default setting for your plots to be private, you can edit your Chart Studio configuration: + +```python +import chart_studio +chart_studio.tools.set_config_file(world_readable=False, + sharing='private') +``` + +For more examples on privacy settings please visit [Python privacy documentation](https://plot.ly/python/privacy/) + + +### Special Instructions for [Chart Studio Enterprise](https://plot.ly/product/enterprise/) Users + + +Your API key for account on the public cloud will be different than the API key in Chart Studio Enterprise. Visit https://plotly.your-company.com/settings/api/ to find your Chart Studio Enterprise API key. Remember to replace "your-company.com" with the URL of your Chart Studio Enterprise server. +If your company has a Chart Studio Enterprise server, change the Python API endpoint so that it points to your company's Plotly server instead of Plotly's cloud. +
+
+In python, enter: + +```python +import chart_studio +chart_studio.tools.set_config_file(plotly_domain='https://plotly.your-company.com', + plotly_streaming_domain='https://stream-plotly.your-company.com') +``` + +Make sure to replace **"your-company.com"** with the URL of *your* Chart Studio Enterprise server. + + +Additionally, you can set your configuration so that you generate **private plots by default**. For more information on privacy settings see: https://plot.ly/python/privacy/
+
+In python, enter: + +```python +import chart_studio +chart_studio.tools.set_config_file(plotly_domain='https://plotly.your-company.com', + plotly_streaming_domain='https://stream-plotly.your-company.com', + world_readable=False, + sharing='private') +``` + +### Plotly Using virtualenv +Python's `virtualenv` allows us create multiple working Python environments which can each use different versions of packages. We can use `virtualenv` from the command line to create an environment using plotly.py version 3.3.0 and a separate one using plotly.py version 2.7.0. See [the virtualenv documentation](https://virtualenv.pypa.io/en/stable) for more info. + +**Install virtualenv globally** +
`$ sudo pip install virtualenv` + +**Create your virtualenvs** +
`$ mkdir ~/.virtualenvs` +
`$ cd ~/.virtualenvs` +
`$ python -m venv plotly2.7` +
`$ python -m venv plotly3.3` + +**Activate the virtualenv.** +You will see the name of your virtualenv in parenthesis next to the input promt. +
`$ source ~/.virtualenvs/plotly2.7/bin/activate` +
`(plotly2.7) $` + +**Install plotly locally to virtualenv** (note that we don't use sudo). +
`(plotly2.7) $ pip install plotly==2.7` + +**Deactivate to exit** +
+`(plotly2.7) $ deactivate` +
`$` + + +### Jupyter Setup +**Install Jupyter into a virtualenv** +
`$ source ~/.virtualenvs/plotly3.3/bin/activate` +
`(plotly3.3) $ pip install notebook` + +**Start the Jupyter kernel from a virtualenv** +
`(plotly3.3) $ jupyter notebook` + + + + +### Start Plotting Online +When plotting online, the plot and data will be saved to your cloud account. There are two methods for plotting online: `py.plot()` and `py.iplot()`. Both options create a unique url for the plot and save it in your Plotly account. +- Use `py.plot()` to return the unique url and optionally open the url. +- Use `py.iplot()` when working in a Jupyter Notebook to display the plot in the notebook. + +Copy and paste one of the following examples to create your first hosted Plotly graph using the Plotly Python library: + +```python +import chart_studio.plotly as py +import plotly.graph_objects as go + +trace0 = go.Scatter( + x=[1, 2, 3, 4], + y=[10, 15, 13, 17] +) +trace1 = go.Scatter( + x=[1, 2, 3, 4], + y=[16, 5, 11, 9] +) +data = [trace0, trace1] + +py.plot(data, filename = 'basic-line', auto_open=True) +``` + +Checkout the docstrings for more information: + +```python +import chart_studio.plotly as py +help(py.plot) +``` + +```python +import chart_studio.plotly as py +import plotly.graph_objects as go + +trace0 = go.Scatter( + x=[1, 2, 3, 4], + y=[10, 15, 13, 17] +) +trace1 = go.Scatter( + x=[1, 2, 3, 4], + y=[16, 5, 11, 9] +) +data = [trace0, trace1] + +py.iplot(data, filename = 'basic-line') +``` + +See more examples in our [IPython notebook documentation](https://plot.ly/ipython-notebooks/) or check out the `py.iplot()` docstring for more information. + +```python +import chart_studio.plotly as py +help(py.iplot) +``` + +You can also create plotly graphs with **matplotlib** syntax. Learn more in our [matplotlib documentation](https://plot.ly/matplotlib/). + + +### Initialization for Offline Plotting +Plotly allows you to create graphs offline and save them locally. There are also two methods for interactive plotting offline: `plotly.io.write_html()` and `plotly.io.show()`. +- Use `plotly.io.write_html()` to create and standalone HTML that is saved locally and opened inside your web browser. +- Use `plotly.io.show()` when working offline in a Jupyter Notebook to display the plot in the notebook. + +For information on all of the ways that plotly figures can be displayed, see [*Displaying plotly figures with plotly for Python*](https://plot.ly/python/renderers/). + + +Copy and paste one of the following examples to create your first offline Plotly graph using the Plotly Python library: + +```python +import plotly.graph_objects as go +import plotly.io as pio + +fig = go.Figure(go.Scatter(x=[1, 2, 3, 4], y=[4, 3, 2, 1])) +fig.update_layout(title_text='hello world') +pio.write_html(fig, file='hello_world.html', auto_open=True) +``` + +Learn more by calling `help()`: + +```python +import plotly +help(plotly.io.write_html) +``` + +```python +import plotly.graph_objects as go +import plotly.io as pio + +fig = go.Figure(go.Scatter(x=[1, 2, 3, 4], y=[4, 3, 2, 1])) +fig.update_layout(title_text='hello world') +pio.show(fig) +``` + +You can also call plotly.io.show directly from the go.Figure object. + +```python +fig.show() +``` + +```python +import plotly +help(plotly.io.show) +``` + +For more examples on plotting offline with Plotly in python please visit our [offline documentation](https://plot.ly/python/offline/). + + +### Using Plotly with Pandas + +To use Plotly with Pandas first `$ pip install pandas` and then import pandas in your code like in the example below. + +```python +import chart_studio.plotly as py +import plotly.graph_objects as go +import pandas as pd + +df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminder2007.csv') + +fig = go.Figure(go.Scatter(x=df.gdpPercap, y=df.lifeExp, text=df.country, mode='markers', name='2007')) +fig.update_xaxes(title_text='GDP per Capita', type='log') +fig.update_yaxes(title_text='Life Expectancy') + +py.iplot(fig, filename='pandas-multiple-scatter') +``` + +### [MORE EXAMPLES](https://plot.ly/python/) +Check out more examples and tutorials for using Plotly in python [here](https://plot.ly/python)! diff --git a/notebooks/ipython-notebook-tutorial.md b/notebooks/ipython-notebook-tutorial.md index 00a7dbeb4..6ede345ff 100644 --- a/notebooks/ipython-notebook-tutorial.md +++ b/notebooks/ipython-notebook-tutorial.md @@ -6,12 +6,13 @@ jupyter: extension: .md format_name: markdown format_version: '1.1' - jupytext_version: 1.1.1 + jupytext_version: 1.1.7 kernelspec: - display_name: Python 2 + display_name: Python 3 language: python - name: python2 + name: python3 plotly: + v4upgrade: true description: Jupyter notebook tutorial on how to install, run, and use Jupyter for interactive matplotlib plotting, data analysis, and publishing code display_as: file_settings @@ -31,7 +32,7 @@ jupyter: [Jupyter](http://jupyter.org/) has a beautiful notebook that lets you write and execute code, analyze data, embed content, and share reproducible work. Jupyter Notebook (previously referred to as IPython Notebook) allows you to easily share your code, data, plots, and explanation in a sinle notebook. Publishing is flexible: PDF, HTML, ipynb, dashboards, slides, and more. Code cells are based on an input and output format. For example: ```python -print "hello world" +print("hello world") ``` #### Installation @@ -90,14 +91,14 @@ Some useful packages that we'll use in this tutorial include: import pandas as pd import numpy as np import scipy as sp -import plotly.plotly as py +import chart_studio.plotly as py ``` #### Import Data You can use pandas `read_csv()` function to import data. In the example below, we import a csv [hosted on github](https://github.com/plotly/datasets/) and display it in a [table using Plotly](https://plot.ly/python/table/): ```python -import plotly.plotly as py +import chart_studio.plotly as py import plotly.figure_factory as ff import pandas as pd @@ -124,8 +125,8 @@ df.std() You can use [Plotly's python API](https://plot.ly/python) to plot inside your Jupyter Notebook by calling ```plotly.plotly.iplot()``` or ```plotly.offline.iplot()``` if working offline. Plotting in the notebook gives you the advantage of keeping your data analysis and plots in one place. Now we can do a bit of interactive plotting. Head to the [Plotly getting started](https://plot.ly/python/) page to learn how to set your credentials. Calling the plot with ```iplot``` automaticallly generates an interactive version of the plot inside the Notebook in an iframe. See below: ```python -import plotly.plotly as py -import plotly.graph_objs as go +import chart_studio.plotly as py +import plotly.graph_objects as go data = [go.Bar(x=df.School, y=df.Gap)] @@ -136,8 +137,8 @@ py.iplot(data, filename='jupyter-basic_bar') Plotting multiple traces and styling the chart with custom colors and titles is simple with Plotly syntax. Additionally, you can control the privacy with [```sharing```](https://plot.ly/python/privacy/) set to ```public```, ```private```, or ```secret```. ```python -import plotly.plotly as py -import plotly.graph_objs as go +import chart_studio.plotly as py +import plotly.graph_objects as go trace_women = go.Bar(x=df.School, y=df.Women, @@ -172,8 +173,8 @@ Now we have interactive charts displayed in our notebook. Hover on the chart to Plotly is now integrated with [Mapbox](https://www.mapbox.com/). In this example we'll plot lattitude and longitude data of nuclear waste sites. To plot on Mapbox maps with Plotly you'll need a Mapbox account and a [Mapbox Access Token](https://www.mapbox.com/studio/signin/) which you can add to your [Plotly settings](). ```python -import plotly.plotly as py -import plotly.graph_objs as go +import chart_studio.plotly as py +import plotly.graph_objects as go import pandas as pd @@ -237,8 +238,8 @@ py.iplot(fig, filename='jupyter-Nuclear Waste Sites on American Campuses') Using Numpy and Plotly, we can make interactive [3D plots](https://plot.ly/python/#3d) in the Notebook as well. ```python -import plotly.plotly as py -import plotly.graph_objs as go +import chart_studio.plotly as py +import plotly.graph_objects as go import numpy as np @@ -291,12 +292,12 @@ Checkout Plotly's [animation documentation](https://plot.ly/python/#animations) Add sliders, buttons, and dropdowns to your inline chart: ```python -import plotly.plotly as py +import chart_studio.plotly as py import numpy as np data = [dict( visible = False, - line=dict(color='00CED1', width=6), + line=dict(color='#00CED1', width=6), name = '𝜈 = '+str(step), x = np.arange(0,10,0.01), y = np.sin(step*np.arange(0,10,0.01))) for step in np.arange(0,5,0.1)] @@ -386,24 +387,6 @@ For more Jupyter tutorials, checkout [Plotly's python documentation](https://plo [![IPython Notebook Gallery](http://i.imgur.com/AdElJQx.png)](https://plot.ly/ipython-notebooks/) -```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( - 'jupyter_tutorial.ipynb', 'python/ipython-notebook-tutorial/', 'Jupyter Notebook Tutorial', - 'Jupyter notebook tutorial on how to install, run, and use Jupyter for interactive matplotlib plotting, data analysis, and publishing code', - title = 'Jupyter Notebook Tutorial | plotly', - name = 'Jupyter Notebook Tutorial', - thumbnail='thumbnail/ipythonnb.jpg', language='python', - page_type='example_index', has_thumbnail='true', display_as='file_settings', order=11, - ipynb='~chelsea_lyn/14070') -``` - ```python ``` diff --git a/notebooks/presentations-tool.md b/notebooks/presentations-tool.md index 48f6dc4d0..574248580 100644 --- a/notebooks/presentations-tool.md +++ b/notebooks/presentations-tool.md @@ -6,12 +6,23 @@ jupyter: extension: .md format_name: markdown format_version: '1.1' - jupytext_version: 1.1.1 + jupytext_version: 1.1.7 kernelspec: - display_name: Python 2 + display_name: Python 3 language: python - name: python2 + 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.6.5 plotly: + v4upgrade: true description: How to create and publish a spectacle-presentation with the Python API. display_as: file_settings @@ -26,19 +37,6 @@ jupyter: title: Presentations Tool | plotly --- -#### New to Plotly? -Plotly's Python library is free and open source! [Get started](https://plot.ly/python/getting-started/) by downloading the client and [reading the primer](https://plot.ly/python/getting-started/). -
You can set up Plotly to work in [online](https://plot.ly/python/getting-started/#initialization-for-online-plotting) or [offline](https://plot.ly/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plot.ly/python/getting-started/#start-plotting-online). -
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started! -#### Version Check -Note: The presentations API is available in version 2.2.1.+
-Run `pip install plotly --upgrade` to update your Plotly version. - -```python -import plotly -plotly.__version__ -``` - #### Plotly Presentations To use Plotly's Presentations API you will write your presentation code in a string of markdown and then pass that through the Presentations API function `pres.Presentation()`. This creates a JSON version of your presentation. To upload the presentation online pass it through `py.presentation_ops.upload()`. @@ -84,8 +82,8 @@ def url_to_iframe(url, text=True): #### Simple Example ```python -import plotly.plotly as py -import plotly.presentation_objs as pres +import chart_studio.plotly as py +import chart_studio.presentation_objs as pres filename = 'simple-pres' markdown_string = """ @@ -126,8 +124,8 @@ The Plotly url lines should be written on a separate line after your title line. For Plotly charts it is HIGHLY ADVISED that you use a chart that has `layout['autosize']` set to `True`. If it is `False` the image may be cropped or only partially visible when it appears in the presentation slide. ```python -import plotly.plotly as py -import plotly.presentation_objs as pres +import chart_studio.plotly as py +import chart_studio.presentation_objs as pres filename = 'pres-with-plotly-chart' markdown_string = """ @@ -164,8 +162,8 @@ IPython.display.HTML(iframe_1) To insert an image from the web, insert the a `Image(url)` where url is the image url. ```python -import plotly.plotly as py -import plotly.presentation_objs as pres +import chart_studio.plotly as py +import chart_studio.presentation_objs as pres filename = 'pres-with-images' markdown_string = """ @@ -203,8 +201,8 @@ IPython.display.HTML(iframe_2) If you want to ensure that your image maintains its original width:height ratio, include the parameter `imgStretch=False` in your `pres.Presentation()` function call. ```python -import plotly.plotly as py -import plotly.presentation_objs as pres +import chart_studio.plotly as py +import chart_studio.presentation_objs as pres filename = 'pres-with-no-imgstretch' markdown_string = """ @@ -230,239 +228,6 @@ iframe_3 = url_to_iframe(pres_url_3, False) IPython.display.HTML(iframe_3) ``` - -#### Insert Code Blocks -The Presentations API also supports the insertion of blocks of code with various available langauges to choose from. - -To instantiate a "code environment" in your string, place a \`\`\` at the beginning of a line, followed by the name of the programming language you want your code block to be styled in. Then the next lines will be considered "code lines ". To close the "code environment" put another \`\`\` at the end of the line For example: - -``` -```python -# code goes here -``` ``` - -The valid languages to choose from are: arecpp, cs, css, fsharp, go, haskell, java, javascript, jsx, julia, xml, matlab, php, python, r, ruby, scala, sql and yaml. - - -```python -import plotly.plotly as py -import plotly.presentation_objs as pres - -filename = 'pres-with-code' -markdown_string = """ -# Getting Started Using Code -A beginner's introduction to computer science. - ---- -# Python Functions -Functions are one of the most useful tools in Python. Intuitively, you select an input and get an output. - -In order to set up a function use the key word "def" then the name of the function with open parentheses afterwards. Inside the parentheses, write variable names your function will use. These variables can then go into the body of your function and when you give a value to the variable in the call signature, it will pass through the guts of the function until it returns a value. - -```python -def somePrintFunction(): - - print("boo") - -somePrintFunction() - - - - ->>>print(new_z) -10 - -def someAddFunction(a, b): - - print(a+b) - - - - ->>>someAddFunction(12,451) -463 -``` ---- -# Use scala -You can write functions in other languages as well. For example, check out this scala code and notice how the print functions look different: - -We write 'println()' as opposed to 'print()' as we do in Python. - -```scala -/** Basic command line parsing. */ -object Main { - var verbose = false - - def main(args: Array[String]) { - for (a <- args) a match { - case "-h" | "-help" => - println("Usage: scala Main [-help|-verbose]") - case "-v" | "-verbose" => - verbose = true - case x => - println("Unknown option: '" + x + "'") - } - if (verbose) - println("How are you today?") - } -} -``` ---- -# Under the Hood - -There are many things to find when you look under the Plotly Hood. Of many things, one expected thing is the compliance and adherance to alphebetized and PEP-8'ed imports at the top of any module. - -This is what the PEP-8 guide has more to say about Imports: - -Wildcard imports (from import *) should be avoided, as they make it unclear which names are present in the namespace, confusing both readers and many automated tools. There is one defensible use case for a wildcard import, which is to republish an internal interface as part of a public API (for example, overwriting a pure Python implementation of an interface with the definitions from an optional accelerator module and exactly which definitions will be overwritten isn't known in advance). - -Image(https://help.plot.ly/images/dashboard-carousel.jpg) - -```python -from __future__ import absolute_import - -import copy -import json -import os -import time -import warnings -import webbrowser - -import six -import six.moves -from requests.compat import json as _json - -from plotly import exceptions, files, session, tools, utils -from plotly.api import v1, v2 -from plotly.plotly import chunked_requests -from plotly.grid_objs import Grid, Column -from plotly.dashboard_objs import dashboard_objs as dashboard -``` -""" - -my_pres = pres.Presentation(markdown_string) -pres_url_4 = py.presentation_ops.upload(my_pres, filename) -``` - -https://plot.ly/~AdamKulidjian/3704/pres-with-code/ - -```python -import IPython - -iframe_4 = url_to_iframe(pres_url_4, True) -IPython.display.HTML(iframe_4) -``` - -#### Style Your Presentation -The Presentations API currently has two styles to choose from: [_Martik_](https://www.pinterest.ca/pin/822540319412564330/) and [_Moods_](https://www.pinterest.ca/pin/822540319412564320/). These themes are inspired by already existing PowerPoint Templates. Let's use the same `markdown_string` in the previous example but this time try the `Martik` style. - -```python -import plotly.plotly as py -import plotly.presentation_objs as pres - -filename = 'martik-style' -markdown_string = """ -# Getting Started Using Code -A beginner's introduction to computer science. - ---- -# Python Functions -Functions are one of the most useful tools in Python. Intuitively, you select an input and get an output. - -In order to set up a function use the key word "def" then the name of the function with open parentheses afterwards. Inside the parentheses, write variable names your function will use. These variables can then go into the body of your function and when you give a value to the variable in the call signature, it will pass through the guts of the function until it returns a value. - -```python -def somePrintFunction(): - - print("boo") - -somePrintFunction() - - - - ->>>print(new_z) -10 - -def someAddFunction(a, b): - - print(a+b) - - - - ->>>someAddFunction(12,451) -463 -``` ---- -# Use scala -You can write functions in other languages as well. For example, check out this scala code and notice how the print functions look different: - -We write 'println()' as opposed to 'print()' as we do in Python. - -```scala -/** Basic command line parsing. */ -object Main { - var verbose = false - - def main(args: Array[String]) { - for (a <- args) a match { - case "-h" | "-help" => - println("Usage: scala Main [-help|-verbose]") - case "-v" | "-verbose" => - verbose = true - case x => - println("Unknown option: '" + x + "'") - } - if (verbose) - println("How are you today?") - } -} -``` ---- -# Under the Hood - -There are many things to find when you look under the Plotly Hood. Of many things, one expected thing is the compliance and adherance to alphebetized and PEP-8'ed imports at the top of any module. - -This is what the PEP-8 guide has more to say about Imports: - -Wildcard imports (from import *) should be avoided, as they make it unclear which names are present in the namespace, confusing both readers and many automated tools. There is one defensible use case for a wildcard import, which is to republish an internal interface as part of a public API (for example, overwriting a pure Python implementation of an interface with the definitions from an optional accelerator module and exactly which definitions will be overwritten isn't known in advance). - -Image(https://help.plot.ly/images/dashboard-carousel.jpg) - -```python -from __future__ import absolute_import - -import copy -import json -import os -import time -import warnings -import webbrowser - -import six -import six.moves -from requests.compat import json as _json - -from plotly import exceptions, files, session, tools, utils -from plotly.api import v1, v2 -from plotly.plotly import chunked_requests -from plotly.grid_objs import Grid, Column -from plotly.dashboard_objs import dashboard_objs as dashboard -``` -""" - -my_pres = pres.Presentation(markdown_string, style='martik') -pres_url_5 = py.presentation_ops.upload(my_pres, 'martik-style') -``` - -```python -import IPython - -iframe_5 = url_to_iframe(pres_url_5, True) -IPython.display.HTML(iframe_5) -``` - #### Transitions You can specify how your want your slides to transition to one another. Just like in the Plotly Presentation Application, there are 4 types of transitions: `slide`, `zoom`, `fade` and `spin`. @@ -480,8 +245,8 @@ transition: slide, zoom ```python -import plotly.plotly as py -import plotly.presentation_objs as pres +import chart_studio.plotly as py +import chart_studio.presentation_objs as pres filename = 'pres-with-transitions' markdown_string = """ @@ -519,72 +284,8 @@ iframe_6 = url_to_iframe(pres_url_6, True) IPython.display.HTML(iframe_6) ``` -#### Add Thin Border Around Text Boxes -Every `slide` has `children`, and each of these `children` have a `style` attribute. This `style` property is derived from the CSS element of the same name. Since you have the power of CSS to work with, you could customize text borders in your presentation if you want. - -```python -import plotly.plotly as py -import plotly.presentation_objs as pres - -filename = 'pres-with-custom-css' -markdown_string = """ -# custom css ---- -transition: zoom, slide, spin, fade -# fun with css - -Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. -```python -x = 4 - -if x < 2: - x = 2 * x - if x >= 2: - break -``` - -""" - -my_pres = pres.Presentation(markdown_string) - -# change text border style -my_pres['presentation']['slides'][1]['children'][0]['props']['style']['border'] = 'solid red' - -pres_url_7 = py.presentation_ops.upload(my_pres, filename) -``` - -https://plot.ly/~AdamKulidjian/3709/pres-with-custom-css/ - -```python -import IPython - -iframe_7 = url_to_iframe(pres_url_7, True) -IPython.display.HTML(iframe_7) -``` - #### Reference ```python help(py.presentation_ops) ``` - -```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( - 'presentations-api.ipynb', 'python/presentations-tool/', 'Presentations Tool | plotly', - 'How to create and publish a spectacle-presentation with the Python API.', - title = 'Presentations Tool | plotly', - name = 'Presentations Tool', - thumbnail='thumbnail/pres_api.jpg', language='python', - has_thumbnail='true', display_as='file_settings', order=0.6) -``` - -```python - -``` diff --git a/notebooks/privacy.md b/notebooks/privacy.md index fb5cd64d9..7cf7cce60 100644 --- a/notebooks/privacy.md +++ b/notebooks/privacy.md @@ -6,12 +6,23 @@ jupyter: extension: .md format_name: markdown format_version: '1.1' - jupytext_version: 1.1.1 + jupytext_version: 1.1.7 kernelspec: - display_name: Python 2 + display_name: Python 3 language: python - name: python2 + 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.6.5 plotly: + v4upgrade: true description: How to set the privacy settings of plotly graphs in python. Three examples of different privacy options: public, private and secret. display_as: file_settings @@ -26,18 +37,6 @@ jupyter: title: Privacy | plotly --- -#### New to Plotly? -Plotly's Python library is free and open source! [Get started](https://plot.ly/python/getting-started/) by downloading the client and [reading the primer](https://plot.ly/python/getting-started/). -
You can set up Plotly to work in [online](https://plot.ly/python/getting-started/#initialization-for-online-plotting) or [offline](https://plot.ly/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plot.ly/python/getting-started/#start-plotting-online). -
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started! -#### Version Check -Plotly's python package is updated frequently. Run `pip install plotly --upgrade` to use the latest version. - -```python -import plotly -plotly.__version__ -``` - #### Default Privacy By default, `plotly.iplot()` and `plotly.plot()` create public graphs (which are free to create). With a [plotly subscription](https://plot.ly/plans) you can easily make charts private or secret via the sharing argument. @@ -45,8 +44,8 @@ By default, `plotly.iplot()` and `plotly.plot()` create public graphs (which are #### Public Graphs ```python -import plotly.plotly as py -import plotly.graph_objs as go +import chart_studio.plotly as py +import plotly.graph_objects as go data = [ go.Scatter( @@ -92,8 +91,8 @@ py.plot(data, filename='privacy-secret', sharing='secret') To make all future plots private, you can update your configuration file to create private plots by default: ```python -import plotly -plotly.tools.set_config_file(world_readable=False, sharing='private') +import chart_studio +chart_studio.tools.set_config_file(world_readable=False, sharing='private') ``` ### Make All Existing Plots Private @@ -152,25 +151,3 @@ make_all_plots_private(username) ```python help(py.plot) ``` - -```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( - 'privacy.ipynb', 'python/privacy/', 'Privacy', - 'How to set the privacy settings of plotly graphs in python. Three examples of different privacy options: public, private and secret.', - title = 'Privacy | plotly', - name = 'Privacy', language='python', - has_thumbnail= True, thumbnail= 'thumbnail/privacy.jpg', - display_as='file_settings', order=2, - ipynb= '~notebook_demo/97') -``` - -```python - -``` diff --git a/notebooks/proxy-configuration.md b/notebooks/proxy-configuration.md new file mode 100644 index 000000000..fb0328206 --- /dev/null +++ b/notebooks/proxy-configuration.md @@ -0,0 +1,79 @@ +--- +jupyter: + jupytext: + notebook_metadata_filter: all + text_representation: + extension: .md + format_name: markdown + format_version: '1.1' + jupytext_version: 1.1.7 + kernelspec: + display_name: Python 3 + 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.6.5 + plotly: + v4upgrade: true + title: requests.exceptions.ConnectionError - Getting Around Corporate Proxies + name: Requests Behind Corporate Proxies + permalink: python/proxy-configuration/ + description: How to configure Plotly's Python API to work with corporate proxies + layout: user-guide + language: python + has_thumbnail: true + thumbnail: thumbnail/net.jpg + display_as: chart_studio + order: 10 +--- + + +If you are behind a corporate firewall, you may see the error message: +``` +requests.exceptions.ConnectionError: ('Connection aborted.', TimeoutError(10060, ...) +``` +Plotly uses the requests module to communicate with the Plotly server. You can configure proxies by setting the environment variables HTTP_PROXY and HTTPS_PROXY. +``` +$ export HTTP_PROXY="http://10.10.1.10:3128" +$ export HTTPS_PROXY="http://10.10.1.10:1080" +``` +To use HTTP Basic Auth with your proxy, use the http://user:password@host/ syntax: + +``` +$ export HTTP_PROXY="http://user:pass@10.10.1.10:3128/" +``` + +Note that proxy URLs must include the scheme. + +You may also see this error if your proxy variable is set but you are no longer behind the corporate proxy. Check if a proxy variable is set with: + +``` +$ echo $HTTP_PROXY +$ echo $HTTPS_PROXY +``` +**Still not working?** + +[Log an issue](https://github.com/plotly/plotly.py) + +Contact [support@plot.ly]() + +Get in touch with your IT department, and ask them about corporate proxies. + +[Requests documentation on configuring proxies](http://docs.python-requests.org/en/latest/user/advanced/#proxies) the requests documentation. + +Plotly for IPython Notebooks is also available for [offline use](https://plot.ly/python/offline/). + +[Chart Studio Enterprise](https://plot.ly/product/enterprise) is available for behind-the-firewall corporate installations. + + +```python + +```