4 Reasons Why I’m Choosing Plotly as My Main Visualization Library
Take your Visualizations to the 21st Century
Mar 23 ·5min read
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.
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:
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.
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:
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.
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 :
Dash Enterprise
Dash Enterprise
Dash Enterprisedash-gallery.plotly.host
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.
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
ppk on JavaScript, 1/e
Peter-Paul Koch / New Riders Press / 2006-09-20 / USD 44.99
Whether you're an old-school scripter who needs to modernize your JavaScripting skills or a standards-aware Web developer who needs best practices and code examples, you'll welcome this guide from a J......一起来看看 《ppk on JavaScript, 1/e》 这本书的介绍吧!