Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python Data Visualization Cookbook (Second Edition)

You're reading from   Python Data Visualization Cookbook (Second Edition) Visualize data using Python's most popular libraries

Arrow left icon
Product type Paperback
Published in Nov 2015
Publisher
ISBN-13 9781784396695
Length 302 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Table of Contents (11) Chapters Close

Preface 1. Preparing Your Working Environment FREE CHAPTER 2. Knowing Your Data 3. Drawing Your First Plots and Customizing Them 4. More Plots and Customizations 5. Making 3D Visualizations 6. Plotting Charts with Images and Maps 7. Using the Right Plots to Understand Data 8. More on matplotlib Gems 9. Visualizations on the Clouds with Plot.ly Index

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:

  1. Generate the data to plot (a sine and a cosine wave).

  2. Organize the data in the format required by Plot.ly.

  3. Send a request to the server.

  4. Receive a URL that points to our chart.

  5. Run the following code:

    import plotly.plotly as py
    from plotly.graph_objs import Scatter
    import numpy as np
    
    x = np.linspace...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime