33

4 Reasons Why I’m Choosing Plotly as the Main Visualization Library

 4 years ago
source link: https://towardsdatascience.com/4-reasons-why-im-choosing-plotly-as-the-main-visualization-library-dc4a961a402f?gi=3464a566bef4
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

4 Reasons Why I’m Choosing Plotly as My Main Visualization Library

Take your Visualizations to the 21st Century

It can be difficult to choose a perfect data visualization platform, as it will heavily depend on which programming language you are the best at, or if you are even willing to use programming languages to make visualizations — as it’s not mandatory.

I7jU3mN.jpg!web

In a world of so many great plotting libraries — especially for the JavaScript users — today I will explain to you why I’m choosing Plotly over everything else.

It might not be something you’ll agree with, but give me a couple of minutes of your time to read through the arguments — it will be worth your time.

Before beginning, I’d just want to say that I’m in no way, shape, or form affiliated with developers behind Plotly nor I’ve been contributing with the development. This article is purely based on personal experience and is aimed to help you with choosing a perfect visualization library for your project.

With that being said, let’s jump into the reasons why you’re here.

#1. It’s Python

Now, you’ll consider this as a benefit only if you know Python already — but since you’re reading a Data Science blog I’m assuming you are.

Python’s syntax is clear, clean, and easy to use, and Plotly is no exception. Just take a look at how little code is needed to produce a simple bubble chart :

import plotly.graph_objects as go
fig = go.Figure(data=go.Scatter(
   x=[1, 2, 3, 4],
   y=[10, 11, 12, 13],
   mode=’markers’,
   marker=dict(size=[40, 60, 80, 100],
               color=[0, 1, 2, 3])
))
fig.show()

Running this code will produce a visually appealing chart shown below:

VJR36n3.png!web

From the docs

It’s not a secret that I’m a fan of Python syntax, but if you aren’t, you can still use Plotly with R and JavaScript . Nevertheless, let’s proceed to the next point.

#2. It’s Interactive

If you’ve followed the first point and executed the provided code, then you’re already aware that visualizations in Plotly are interactive.

RBJRJbm.jpg!web

Photo by Isaac Smith on Unsplash

Maybe that’s not a huge thing to you if you’re coming from a JavaScript background, but it’s a huge thing for anyone coming from Python. Visualizations made through Matplotlib are not interactive, and look pretty much worse by default than default visualizations from Plotly.

You don’t need to specify that you want your chart to be interactive, but you sure can tweak what is visible on hover.

More on that in later articles, there are many more to come in this Plotly series.

#3. Clear Syntax

Your Plotly chart will have a Figure object, populated with:

Data
Layout

As you might figure, you’ll put the data which makes the charts in the data , and in layout you’ll specify how the chart should look like. Let’s take a look at an example.

Let’s make a few imports first:

import numpy as np
np.random.seed(42)
import plotly.offline as pyo
import plotly.graph_objs as go

Now let’s define the data which will go into the chart:

x = np.random.randint(1, 101, 100)
y = np.random.randint(1, 101, 100)data = [go.Scatter(
    x=x,
    y=y,
    mode='markers',
)]

That’s it. This will create a scatter plot from random integers on both the x-axis and the y-axis. Now let’s define the layout :

layout = go.Layout(
    title=’Plot title’,
    xaxis=dict(title=’X-Axis’),
    yaxis=dict(title=’Y-Axis’),
    hovermode=’closest’
)

And now let’s put everything into a Figure object and plot it:

fig = go.Figure(data=data, layout=layout)
pyo.plot(fig)

If you ask me that was as clean as data visualization can be. If you were to take this code, put it in a single .py script and run it, the visualization would be saved as a html file and automatically opened in your browser:

UVJBRjv.png!web

Not too shabby, but we’ll dive much deeper into styling in the following articles.

#4. Dashboards

If you know some basic HTML and CSS then it’s very easy to incorporate multiple charts into a single, good-looking dashboard.

7rU3A3b.jpg!web

Photo by Carlos Muza on Unsplash

Plotly charts can be incorporated with Dash , a framework for building web applications .

Here’s a paragraph from the official documentation:

Written on top of Flask, Plotly.js, and React.js, Dash is ideal for building data visualization apps with highly custom user interfaces in pure Python. It’s particularly suited for anyone who works with data in Python.

This React part will transform your app into a Single Page Application , meaning that there won’t be those awkward refreshes upon clicking on stuff. And all of this without knowing any web development. Awesome.

We won’t dive into dashboard development now, but few articles down the road will cover it in depth.

If you can’t wait to see what can be produced with Dash , here’s the official gallery :

Before you go

I’m perfectly fine with looking at the tabular data. But a big part of my job is presenting findings and conclusion to others, and every single time showing a chart will be a far more effective method.

In the next month or so I’ve decided to publish 10-ish articles that will cover Plotly and Dash front to back, making sure that data visualization won’t be a painful process to you in the future.

Thanks for reading and stay tuned.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK