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

栏目: IT技术 · 发布时间: 5年前

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.

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

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:

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

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.

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

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:

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

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.

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

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.


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

创业时代

创业时代

付遥 / 中信出版社 / 2015-7 / 39.8元

香港人郭鑫年酷爱赛车,在驾车穿越隧道的时候,因为收发短信发生意外,他从被撞得破烂的车里爬出来时,兴奋地高喊:我有一个伟大的想法,手机上的对讲机,将要改变世界!他随即辞职来到北京,开始艰难的创业历程。 移动技术迅猛发展,正在颠覆互联网行业,郭鑫年误打误撞,对讲机用户数量急增,竟成为移动互联网的明星,他也因此置身于风口浪尖。三大互联网巨头为了抢夺手机入口大打出手,无不希望争夺这张通往未来移动市场......一起来看看 《创业时代》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

html转js在线工具
html转js在线工具

html转js在线工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具