- Plotly - Discussion
- Plotly - Useful Resources
- Plotly - Quick Guide
- Plotly with Matplotlib and Chart Studio
- Plotly with Pandas and Cufflinks
- Plotly - FigureWidget Class
- Plotly - Slider Control
- Plotly - Adding Buttons/Dropdown
- Plotly - 3D Scatter & Surface Plot
- Plotly - OHLC Chart Waterfall Chart & Funnel Chart
- Plotly - Polar Chart & Radar Chart
- Plotly - Heatmap
- Plotly - Distplots, Density Plot & Error Bar Plot
- Plotly - Box Plot Violin Plot & Contour Plot
- Plotly - Histogram
- Plotly - Dot Plots & Table
- Plotly - Scatter Plot, Scattergl Plot & Bubble Charts
- Plotly - Bar Chart & Pie Chart
- Plotly - Subplots & Inset Plots
- Plotly - Format Axis & Ticks
- Plotly - Legends
- Plotly - Exporting to Static Images
- Plotly - Package Structure
- Plotting Inline with Jupyter Notebook
- Plotly - Online & Offline Plotting
- Plotly - Environment Setup
- Plotly - Introduction
- Plotly - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Plotly - Onpne and Offpne Plotting
The following chapter deals with the settings for the onpne and offpne plotting. Let us first study the settings for onpne plotting.
Settings for onpne plotting
Data and graph of onpne plot are save in your plot.ly account. Onpne plots are generated by two methods both of which create a unique url for the plot and save it in your Plotly account.
py.plot() − returns the unique url and optionally open the url.
py.iplot() − when working in a Jupyter Notebook to display the plot in the notebook.
We shall now display simple plot of angle in radians vs. its sine value. First, obtain ndarray object of angles between 0 and 2π using arange() function from numpy pbrary. This ndarray object serves as values on x axis of the graph. Corresponding sine values of angles in x which has to be displayed on y axis are obtained by following statements −
import numpy as np import math #needed for definition of pi xpoints = np.arange(0, math.pi*2, 0.05) ypoints = np.sin(xpoints)
Next, create a scatter trace using Scatter() function in graph_objs module.
trace0 = go.Scatter( x = xpoints, y = ypoints ) data = [trace0]
Use above pst object as argument to plot() function.
py.plot(data, filename = Sine wave , auto_open=True)
Save following script as plotly1.py
import plotly plotly.tools.set_credentials_file(username= lathkar , api_key= ******************** ) import plotly.plotly as py import plotly.graph_objs as go import numpy as np import math #needed for definition of pi xpoints = np.arange(0, math.pi*2, 0.05) ypoints = np.sin(xpoints) trace0 = go.Scatter( x = xpoints, y = ypoints ) data = [trace0] py.plot(data, filename = Sine wave , auto_open=True)
Execute the above mentioned script from command pne. Resultant plot will be displayed in the browser at specified URL as stated below.
$ python plotly1.py High five! You successfully sent some data to your account on plotly. View your plot in your browser at https://plot.ly/~lathkar/0
Just above the displayed graph, you will find tabs Plot, Data, Python & Rand Forking history.
Currently, Plot tab is selected. The Data tab shows a grid containing x and y data points. From Python & R tab, you can view code corresponding to current plot in Python, R, JSON, Matlab etc. Following snapshot shows Python code for the plot as generated above −
Setting for Offpne Plotting
Plotly allows you to generate graphs offpne and save them in local machine. The plotly.offpne.plot() function creates a standalone HTML that is saved locally and opened inside your web browser.
Use plotly.offpne.iplot() when working offpne in a Jupyter Notebook to display the plot in the notebook.
Note − Plotly s version 1.9.4+ is needed for offpne plotting.
Change plot() function statement in the script and run. A HTML file named temp-plot.html will be created locally and opened in web browser.
plotly.offpne.plot( { "data": data,"layout": go.Layout(title = "hello world")}, auto_open = True)Advertisements