Creating line charts
In this recipe, we will see how to create a line chart. We have already introduced this kind of chart in Chapter 3, Drawing Your First Plots and Customizing Them, and we have seen how to make the plots with matplotlib. This time we'll focus on how to create and share them with Plot.ly.
Getting ready
Before starting, you need to set up your credentials for the Plot.ly platform in the programming environment:
$ python -c "import plotly; plotly.tools.set_credentials_file(username='DemoAccount', api_key='mykey')"
Replace Demo Account
and mykey
with your Plotly username and API key.
How to do it...
The following code example demonstrates how to plot two curves. In particular, we will:
Generate the data to plot (a sine and a cosine wave).
Organize the data in the format required by Plot.ly.
Send a request to the server.
Receive a URL that points to our chart.
Run the following code:
import plotly.plotly as py from plotly.graph_objs import Scatter import numpy as np x = np.linspace...