Charting with Plotly

What is Plotly?

Plotly is an online analytics and data visualization tool, headquartered in Montreal, Quebec. Plotly provides online graphing, analytics, and stats tools for individuals and collaboration, as well as scientific graphing libraries for Python, R, MATLAB, Perl, Julia, Arduino, and REST.

Plotly was built using Python and the Django framework, with a front end using JavaScript and the visualization library D3.js, HTML and CSS. Files are hosted on Amazon S3.

Other chartbuilders out there

Why Plotly

  • Plot.ly has a graphical user interface for importing and analyzing data into a grid and using stats tools.
  • Graphs can be embedded or downloaded.
  • API libraries for Python, R, MATLAB, Node.js, Julia, and Arduino and a REST API.
  • Figure Converters which convert matplotlib, ggplot2, and IGOR Pro graphs into interactive, online graphs.

Sign up

Create an account

Visit the Plotly feed page

Welcome to [plot.ly/feed](https://plot.ly/feed/)

This is where all the recent charts people have made are displayed.

Click on any of the examples to see how they were made

Click on the **DATA** tab

Now you can see the underlying data structure behind the visualization.

Or click on Fork & Edit

Click SAVE if you want to save a copy of it to your list of projects.

Make a chart

Let’s start from scratch.

Click on the **+Create** button at the top right]

And select Chart.

Preparing the data

Let’s use the Hamilton grosses data.

Visit their page and copy the data in the table.

Paste it into the table grid

On the left, click the pulldown menu in Chart Type and click line plot.

For the X, select column A.

For the Y, select column B

Hm, something looks off.

According to this chart, Hamilton is making less money over time. Does that make sense?

Take a look at the X axis.

There's the problem.

It’s going in the opposite direction.

What happens if we try to sort it?

Not good.

It sorts the column alphabetically.

It doesn’t realize that it’s a date.

Note This is the scourge of working with data. The programs you’ll work with will do its best (or not try at all) to guess what format the data you’re trying to use is. But often times it gets it wrong, so it’s up to us humans to tell the program what the data is so it will do what we want to do with it.

We need to turn that dates column into a format that can be sorted easily.

Let’s go back to the Hamilton data page and this time copy and paste the data into a Google Sheet.

This looks familiar.

If it is going to sort ascending and descending, we need to change the format so that when it sorts, it does so logically.

So we need to tell Google Sheets to transform the dates column into years, months, and date.

Because that numerical order will sort correctly.

Click Format > and look for the format 2008-09-26 because that’s the best way (Not the Date 9/26/2008 option because if you think about it, it will group the months from different years together, which is not correct)

The proper date format.

Great!

Bring that data back into Plotly.

The proper format.

Before we move on, let’s clean things up a bit.

We want to give the header columns the proper names.

Right click the space next to the header column and select Use row as header.

This makes the labels in the first row the header column.

But now we’ve got an extra row that will only mess things up when we visualize the data.

So get rid of it.

Right click the row header next to it and select Remove selected rows.

Now the row is gone.

Before we try to chart it, don’t forget to sort the dates column ascending.

Sorting.

On the left, click the pulldown menu in Chart Type and click line plot.

For the X, select column Week Ending.

For the Y, select column Gross.

For Hover Text, select column Gross.

Click into the title and now you’ve got a chart!

Ta da!

You can style it more with the Style tab on the left.

Click Save and name the plot and data file for future reference.

Who knows when you'll need it again.

You’ll get a link, and when you follow it, click the Export button.

You've got a lot of options now.

If you want, you can save it as an image and edit it in Photoshop or Illustrator.

Or you can take the embed code and put it in a website.