#!/usr/bin/env python # coding: utf-8 # #### New to Plotly? # Plotly's Python library is free and open source! [Get started](https://plotly.com/python/getting-started/) by downloading the client and [reading the primer](https://plotly.com/python/getting-started/). #
You can set up Plotly to work in [online](https://plotly.com/python/getting-started/#initialization-for-online-plotting) or [offline](https://plotly.com/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plotly.com/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! # #### Create a Simple FigureWidget # Create an empty FigureWidget and then view it. # In[ ]: import plotly.graph_objs as go f = go.FigureWidget() f # # Add traces or update the layout and then watch the output above update in real time. # In[ ]: f.add_scatter(y=[2, 1, 4, 3]) # In[ ]: f.add_bar(y=[1, 4, 3, 2]) # In[6]: f.layout.title = 'Hello FigureWidget' # # #### Update the Data and the Layout # In[8]: # update scatter data scatter = f.data[0] scatter.y = [3, 1, 4, 3] # In[9]: # update bar data bar = f.data[1] bar.y = [5, 3, 2, 8] # In[10]: f.layout.title = 'This is a new title' # #### Construct a FigureWidget With Data and Layout Arguments # We can construct a FigureWidget with the same arguments that `py.iplot` and `py.plot` use in order to convert an example of the latter using go.FigureWidget and we can also use a FigureWidget in the argument of iplot. # Using *Data* and *Layout*: # In[11]: import plotly.offline as py py.init_notebook_mode() trace = go.Heatmap(z=[[1, 20, 30, 50, 1], [20, 1, 60, 80, 30], [30, 60, 1, -10, 20]], x=['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'], y=['Morning', 'Afternoon', 'Evening']) data=[trace] layout = go.Layout(title='Activity Heatmap') f2 = go.FigureWidget(data,layout) # two different ways to view f2 py.iplot(f2) f2 # Construct using a `go.Figure` object: # In[12]: figure = go.Figure(data=data, layout=layout) f3 = go.FigureWidget(figure) # #### Reference # See [these Jupyter notebooks](https://github.com/jonmmease/plotly_ipywidget_notebooks) for even more FigureWidget examples. # In[13]: help(go.FigureWidget) # In[14]: from IPython.display import display, HTML display(HTML('')) display(HTML('')) get_ipython().system(' pip install git+https://github.com/plotly/publisher.git --upgrade') import publisher publisher.publish( 'figurewidget-overview.ipynb', 'python/figurewidget/', 'FigureWidget | Plotly', 'Introduction to the new Plotly FigureWidget', title = 'Plotly FigureWidget Overview', name = 'Plotly FigureWidget Overview', uses_plotly_offline=True, has_thumbnail='true', thumbnail='thumbnail/figurewidget-overview.gif', language='python', page_type='example_index', display_as='chart_events', order=0, ipynb= '~notebook_demo/235') # In[ ]: