基于plotly数据可视化_如何使用Plotly进行数据可视化

基于plotly数据可视化

The amount of data in the world is growing every second. From sending a text to clicking a link, you are creating data points for companies to use. Insights that can be drawn from this collection of data can be extremely valuable. Every business has their own storage of data that they need to examine. One of the most important ways this examination is done is by visualizing the data.

吨他达到世界数据的增长每一秒。 从发送文本到单击链接,您正在创建供公司使用的数据点。 从这些数据收集中得出的见解可能非常有价值。 每个企业都有自己需要检查的数据存储。 进行此检查的最重要方法之一是可视化数据。

为什么要可视化数据? (Why Visualize Data?)

Simply put — “a picture is worth a thousand words”. In the entire history of business, data visualization has remained a necessary component. The reason it is so necessary is ultimately because we are visual creatures. Why else do you think a majority of us would prefer to watch a movie adaptation of a book than read the book itself? In terms of business presentations, a graph or chart of sales data may prove more insightful than just plain text. It is easy to draw insights from visual mediums rather than word documents.

简而言之-“ 一张图片值得一千个字 ”。 在整个业务历史中,数据可视化仍然是必不可少的组成部分。 之所以如此必要,是因为我们最终是视觉生物。 您为什么还认为我们大多数人宁愿看电影改编电影也不愿看书本身? 就业务演示而言,销售数据的图形或图表可能会证明比纯文本更具洞察力。 从视觉媒介而不是单词文档中汲取见解很容易。

By visualizing the data you are making the data more accessible to a wider audience. This can help draw more insights because someone else might have an insight or two that you may never have thought of. The more people that see your visualization, then the more insights can potentially be made.

通过可视化数据,您可以使更广泛的受众更容易访问数据。 这可以帮助您获得更多的见解,因为其他人可能有您可能从未想过的一两个见识。 看到您的可视化内容的人越多,则可以潜在地获得更多的见解。

Image for post
Photo by Austin Distel on Unsplash
Austin Distel在Unsplash上拍摄的照片

Visualizations also play a key role when presenting to crucial decision makers such as board members or shareholders. As you are constructing your numerous graphs and plots to highlight key data points, the visuals you decide to make can help push these decision makers in one direction or another. If the data visuals are presented with a select narrative in mind, then these decision makers will be inclined to make specific decisions based on your presentation.

在向关键决策者(例如董事会成员或股东)展示时,可视化也起着关键作用。 在构建大量图形和图表以突出显示关键数据点时,您决定制作的视觉效果可以帮助将这些决策者推向一个方向或另一个方向。 如果在呈现数据视觉效果时考虑了特定的叙述,那么这些决策者将倾向于根据您的呈现做出特定的决策。

数据可视化工具 (Tools for Data Visualization)

Pie charts, bar charts, line graphs, and so on are all effective visuals when presenting data. These visuals are the tried and true forms for data presentation and we have made it even easier to create them. What we once use to do by hand can now be done with a couple of clicks on a computer.

饼图,条形图,折线图等都是呈现数据时的有效视觉效果。 这些视觉效果是经过验证的真实数据展示形式,我们使创建它们变得更加容易。 现在,我们曾经手动执行的操作现在只需在计算机上单击几下即可完成。

Nowadays, we have access to multiple programs to construct beautiful looking charts and graphs. These tools range from more technically based applications of visualization like Python’s Matplotlib or Plotly to more user-friendly ones like Tableau or Microsoft Power BI. Data visualizations tools are now more accessible than ever before.

如今,我们可以使用多个程序来构建美观的图表。 这些工具的范围从更基于技术的可视化应用程序(例如Python的MatplotlibPlotly)到更加用户友好的工具(如TableauMicrosoft Power BI) 。 数据可视化工具现在比以往任何时候都更易于访问。

Image for post
Photo by Katie Rodriguez on Unsplash
凯蒂·罗德里格斯 ( Katie Rodriguez)在Unsplash上的照片

Within the realm of Python programming, there are many different libraries you could use to craft data visualizations. These libraries include, but are not limited, to Altair, Seaborn, and Plotly. There is no superior Python library because it all depends on what you are comfortable with and the problem or data you are trying to visualize.

在Python编程领域内,可以使用许多不同的库来制作数据可视化。 这些库包括但不限于AltairSeabornPlotly 。 没有出色的Python库,因为这一切都取决于您是否熟悉什么以及要可视化的问题或数据。

学习如何使用情节 (Learning How to Use Plotly)

One of the tools we mentioned before is called Plotly. Plotly is a graphing and plotting library in Python similar to Matplotlib. The difference between the two is the fact that Plotly creates dynamically, interactive charts and graphs.

我们之前提到的工具之一称为Plotly 。 Plotly是Python中的绘图和绘图库,类似于Matplotlib。 两者之间的区别在于Plotly创建动态的交互式图表的事实。

一个简单的业务问题 (A Simple Business Problem)

To get started with Plotly, we will need data to graph or plot first. So let’s say for example you work for a business that sells clothing. They want you to chart the sales for their shirts and jeans over the course of one year and have provided you with the data to do so. This problem will help us begin working with Plotly.

要开始使用Plotly,我们将需要首先绘制图形或绘图的数据。 举例来说,假设您为一家销售服装的公司工作。 他们希望您绘制一年中衬衫和牛仔裤的销售图表,并提供了相关数据。 这个问题将帮助我们开始使用Plotly。

剧情安装 (Installing Plotly)

In order to begin, we must first install Plotly by using the following command in your terminal:

首先,我们必须首先在终端中使用以下命令来安装Plotly:

$ pip install plotly

Or if you have Anaconda installed:

或者,如果您安装了Anaconda

$ conda install -c plotly plotly

导入 (Importing Plotly)

Now that you have Plotly installed, let’s open a new file and start importing the necessary libraries for our data visualization example:

现在您已经安装了Plotly,让我们打开一个新文件,并开始为数据可视化示例导入必要的库:

import plotly.express as px
import calendar as cal
import random
import pandas as pd

Here we are using plotly.express, which is a module within Plotly that will quickly create graphs and charts for us.

在这里,我们使用plotly.express ,它是plotly.express中的一个模块,可以为我们快速创建图形和图表。

创建数据 (Creating the Data)

Since we are not actually given real data, we will have to create our own:

由于实际上并未提供真实数据,因此我们将必须创建自己的数据:

data = {'Months': [cal.month_name[i] for i in range(1,13)],
'Shirts': [round(random.gauss(100, 15)) for _ in range(12)],
'Jeans': [round(random.gauss(50, 20)) for _ in range(12)]}

Plotly works very well with Pandas DataFrames so we will store our newly created data into a DF:

Plotly与Pandas DataFrames配合得很好,因此我们会将新创建的数据存储到DF中:

df = pd.DataFrame(data)

This new DF looks like this:

这个新的DF看起来像这样:

Image for post
Our DF for Plotly
我们的DF情节

情节的条形图 (Plotly’s Bar Chart)

Now that we have our DF ready we can begin crafting our bar chart:

现在我们已经准备好DF,可以开始制作条形图了:

fig = px.bar(df, 
x='Months',
y=['Shirts','Jeans'])fig.show()

Here we are using the .bar() method and inputting the DF of our data, and specifying the x and y axes. We are crafting a stacked bar chart by making a list for the columns: ‘Shirts’ and ‘Jeans’. Which we’ll display by calling fig.show().

在这里,我们使用.bar()方法并输入数据的DF,并指定xy轴。 我们通过列出以下列的列表来制作堆叠式条形图:“ Shirts ”和“ Jeans ”。 我们将通过调用fig.show()显示。

Image for post

Success! That was simple enough. The cool thing about this Plotly chart is that you can start interacting with it by zooming in, panning, etc. But in regards to the overall chart, there are some things we would like to change to make this graph a little bit more descriptive like adding a title and renaming a few of the labels.

成功! 那很简单。 关于该Plotly图表,最酷的事情是您可以通过放大,平移等开始与之交互。但是对于整体图表,我们需要进行一些更改以使该图表更具描述性,例如添加标题并重命名一些标签。

fig = px.bar(df, 
x='Months',
y=['Shirts','Jeans'],
title='Total Monthly Item Sales',
labels={'variable': 'Item',
'value': 'Quantity Sold (in thousands)'})fig.show()

The difference between this code and the code before is the addition of the title= and labels={} argument. With these new arguments we are adding in a title for the chart and under the labels we are basically using a dictionary to replace the two current labels.

此代码与之前的代码之间的区别是添加了title=labels={}参数。 通过这些新参数,我们为图表添加了一个标题,在labels之下,我们基本上是使用字典来替换两个当前标签。

Image for post
Updated bar chart with correct labels and title
更新了带有正确标签和标题的条形图

Now that the bar chart is properly labeled, we are basically finished with using Plotly for this data. But what if we wanted to do other kinds of charts or graphs in order to view different sides of the data?

现在,条形图已正确标记,我们基本上已经完成了对数据使用Plotly的操作。 但是,如果我们想做其他种类的图表来查看数据的不同方面怎么办?

情节的线图 (Plotly’s Line Graph)

Plotly allows us to create other types of visualizations too. We can easily create a line graph by using the code from before and just changing one thing:

通过Plotly,我们也可以创建其他类型的可视化。 我们可以使用之前的代码轻松地创建折线图,而只需更改一件事:

fig = px.line(df, 
x='Months',
y=['Shirts','Jeans'],
title='Monthly Item Sales',
labels={'variable': 'Item',
'value': 'Quantity Sold (in thousands)'})fig.show()

All we did here was change px.bar to px.line. This now displays the following:

我们在这里所做的只是将px.bar更改为px.line 。 现在将显示以下内容:

Image for post
A line graph with the same data
具有相同数据的折线图

Now we have a line graph! But wait there’s more…

现在我们有了折线图! 但是,等等……

情节饼图 (Plotly’s Pie Chart)

Let’s say we wanted to compare how many shirts were sold vs how many jeans were sold in the entire year.

假设我们要比较全年售出的衬衫数量与牛仔裤的销售数量。

First, we must change our data to show the total sum of all sales for shirts and jeans:

首先,我们必须更改数据以显示衬衫和牛仔裤的所有销售总额:

pie_df = df[['Shirts','Jeans']].sum()

Here we’re just getting the sum of both Shirts and Jeans from the DF. Then, we will need to use px.pie() using our new summed up DF.

在这里,我们只是从DF中获取ShirtsJeans的总和。 然后,我们需要使用新的汇总DF使用px.pie()

fig = px.pie(values=pie_df.values, 
names=pie_df.index,
title="Sales Percentage in a Year")fig.show()

The argument values is used to determine the sizes of each portion of the pie chart. The names are the labels for each of the portions.

参数values用于确定饼图各部分的大小。 names是每个部分的标签。

Image for post
Our pie chart of the data
我们的数据饼图

Awesome! Now we have created three different types of visualizations for our data. But you don’t have to stop — there are more options available (see here for more) if you feel the need to continue experimenting with Plotly.

太棒了! 现在,我们为数据创建了三种不同类型的可视化。 但是您不必停下来-如果您有需要继续尝试Plotly的权利,可以使用更多选项( 有关更多信息, 请参见此处 )。

数据见解和结论 (Data Insights and Conclusions)

After visualizing our data, we would need to come to some sort of insight or conclusion based on the visuals. What can you tell based on these charts? Are there some obvious conclusions that can be drawn? What about some not so obvious ones?

可视化我们的数据后,我们需要根据视觉效果得出某种见解或结论。 您可以根据这些图表看出什么? 是否可以得出一些明显的结论? 那些不太明显的东西呢?

Anyways, insights and conclusions are easier to see rather than read. If you are still wondering about the importance of visualizations, then just take a look back at the DF we created and compare it to any of the visuals we created with Plotly. Sometimes reading information is not as good as seeing the information.

无论如何,见解和结论更容易看到而不是阅读。 如果您仍然想知道可视化的重要性,那么只需回顾一下我们创建的DF,并将其与我们使用Plotly创建的任何可视化图像进行比较。 有时阅读信息不如阅读信息。

翻译自: https://towardsdatascience.com/how-to-use-plotly-for-data-visualization-f3d62bbcfd92

基于plotly数据可视化

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/388164.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

ESLint简介

ESLint简介 ESLint是一个用来识别 ECMAScript 并且按照规则给出报告的代码检测工具,使用它可以避免低级错误和统一代码的风格。如果每次在代码提交之前都进行一次eslint代码检查,就不会因为某个字段未定义为undefined或null这样的错误而导致服务崩溃&…

数据科学与大数据是什么意思_什么是数据科学?

数据科学与大数据是什么意思Data Science is an interdisciplinary field that uses a combination of code, statistical analysis, and algorithms to gain insights from structured and unstructured data.数据科学是一个跨学科领域,它结合使用代码,…

C#制作、打包、签名、发布Activex全过程

一、前言 最近有这样一个需求,需要在网页上面启动客户端的软件,软件之间的通信、调用,单单依靠HTML是无法实现了,因此必须借用Activex来实现。由于本人主要擅长C#,自然本文给出了用C#实现的范例,本文的预期…

用Python创建漂亮的交互式可视化效果

Plotly is an interactive Python library that provides a wide range of visualisations accessible through a simple interface.Plotly是一个交互式Python库,通过简单的界面即可提供广泛的可视化效果。 There are many different visualisation libraries avai…

Hadoop 2.0集群配置详细教程

Hadoop 2.0集群配置详细教程 前言 Hadoop2.0介绍 Hadoop是 apache 的开源 项目,开发的主要目的是为了构建可靠,可拓展 scalable ,分布式的系 统, hadoop 是一系列的子工程的 总和,其中包含 1. hadoop common &#xff…

php如何减缓gc_管理信息传播-使用数据科学减缓错误信息的传播

php如何减缓gcWith more people now than ever relying on social media to stay updated on current events, there is an ethical responsibility for hosting companies to defend against false information. Disinformation, which is a type of misinformation that is i…

[UE4]删除UI:Remove from Parent

同时要将保存UI的变量清空,以释放占用的系统内存 转载于:https://www.cnblogs.com/timy/p/9842206.html

BZOJ2503: 相框

Description P大的基础电路实验课是一个无聊至极的课。每次实验,T君总是提前完成,管理员却不让T君离开,T君只能干坐在那儿无所事事。先说说这个实验课,无非就是把几根导线和某些元器件(电阻、电容、电感等)…

泰坦尼克号 数据分析_第1部分:泰坦尼克号-数据分析基础

泰坦尼克号 数据分析My goal was to get a better understanding of how to work with tabular data so I challenged myself and started with the Titanic -project. I think this was an excellent way to learn the basics of data analysis with python.我的目标是更好地了…

vba数组dim_NDArray — —一个基于Java的N-Dim数组工具包

vba数组dim介绍 (Introduction) Within many development languages, there is a popular paradigm of using N-Dimensional arrays. They allow you to write numerical code that would otherwise require many levels of nested loops in only a few simple operations. Bec…

关于position的四个标签

四个标签是static,relative,absolute,fixed。 static 该值是正常流,并且是默认值,因此你很少看到(如果存在的话)指定该值。 relative:框的位置能够相对于它在正常流中的位置有所偏移…

python算法和数据结构_Python中的数据结构和算法

python算法和数据结构To至 Leonardo da Vinci达芬奇(Leonardo da Vinci) 介绍 (Introduction) The purpose of this article is to give you a panorama of data structures and algorithms in Python. This topic is very important for a Data Scientist in order to help …

CSS:元素塌陷问题

2019独角兽企业重金招聘Python工程师标准>>> 描述: 在文档流中,父元素的高度默认是被子元素撑开的,也就是子元素多高,父元素就多高。但是当子元素设置浮动之后,子元素会完全脱离文档流,此时将会…

Celery介绍及常见错误

celery 情景:用户发起request,并等待response返回。在本些views中,可能需要执行一段耗时的程序,那么用户就会等待很长时间,造成不好的用户体验,比如发送邮件、手机验证码等。 使用celery后,情况…

python dash_Dash是Databricks Spark后端的理想基于Python的前端

python dash📌 Learn how to deliver AI for Big Data using Dash & Databricks this recorded webinar with Peter Kim of Plotly and Prasad Kona of Databricks.this通过Plotly的Peter Kim和Databricks的Prasad Kona的网络研讨会了解如何使用Dash&#xff06…

Eclipse 插件开发遇到问题心得总结

Eclipse 插件开发遇到问题心得总结 Posted on 2011-07-17 00:51 季枫 阅读(3997) 评论(0) 编辑 收藏1、Eclipse 中插件开发多语言的实现 为了使用 .properties 文件,需要在 META-INF/MANIFEST.MF 文件中定义: Bundle-Localization: plugin 这样就会…

在Python中查找子字符串索引的5种方法

在Python中查找字符串中子字符串索引的5种方法 (5 Ways to Find the Index of a Substring in Strings in Python) str.find() str.find() str.rfind() str.rfind() str.index() str.index() str.rindex() str.rindex() re.search() re.search() str.find() (str.find()) …

Eclipse 插件开发 向导

阅读目录 最近由于特殊需要,开始学习插件开发。   下面就直接弄一个简单的插件吧!   1 新建一个插件工程   2 创建自己的插件名字,这个名字最好特殊一点,一遍融合到eclipse的时候,不会发生冲突。   3 下一步,进…

线性回归 假设_线性回归的假设

线性回归 假设Linear Regression is the bicycle of regression models. It’s simple yet incredibly useful. It can be used in a variety of domains. It has a nice closed formed solution, which makes model training a super-fast non-iterative process.线性回归是回…

solo

solo - 必应词典 美[soʊloʊ]英[səʊləʊ]n.【乐】独奏(曲);独唱(曲);单人舞;单独表演adj.独唱[奏]的;单独的;单人的v.独奏;放单飞adv.独网络梭罗;独奏曲;索罗变形复数&#xff1…