基于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.

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

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) 。 数据可视化工具现在比以往任何时候都更易于访问。

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 pximport calendar as calimport randomimport 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看起来像这样:

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()显示。

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之下,我们基本上是使用字典来替换两个当前标签。

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 。 现在将显示以下内容:

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是每个部分的标签。

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.taodudu.cc/news/show-994856.html

相关文章:

  • 用Python创建漂亮的交互式可视化效果
  • php如何减缓gc_管理信息传播-使用数据科学减缓错误信息的传播
  • 泰坦尼克号 数据分析_第1部分:泰坦尼克号-数据分析基础
  • vba数组dim_NDArray — —一个基于Java的N-Dim数组工具包
  • python算法和数据结构_Python中的数据结构和算法
  • python dash_Dash是Databricks Spark后端的理想基于Python的前端
  • 在Python中查找子字符串索引的5种方法
  • 趣味数据故事_坏数据的好故事
  • python分句_Python循环中的分句,继续和其他子句
  • python数据建模数据集_Python中的数据集
  • usgs地震记录如何下载_用大叶草绘制USGS地震数据
  • 数据可视化 信息可视化_更好的数据可视化的8个技巧
  • sql 左联接 全联接_通过了解自我联接将您SQL技能提升到一个新的水平
  • 科学价值 社交关系 大数据_服务的价值:数据科学和用户体验研究美好生活
  • vs azure web_在Azure中迁移和自动化Chrome Web爬网程序的指南。
  • selenium 解析网页_用Selenium进行网页搜刮
  • hive 导入hdfs数据_将数据加载或导入运行在基于HDFS的数据湖之上的Hive表中的另一种方法。
  • 大数据业务学习笔记_学习业务成为一名出色的数据科学家
  • python 开发api_使用FastAPI和Python快速开发高性能API
  • Power BI:M与DAX以及度量与计算列
  • 梯度下降法优化目标函数_如何通过3个简单的步骤区分梯度下降目标函数
  • seaborn 子图_Seaborn FacetGrid:进一步完善子图
  • 异常检测时间序列_时间序列的无监督异常检测
  • 存款惊人_如何使您的图快速美丽惊人
  • 网络传播动力学_通过简单的规则传播动力
  • 开源软件 安全风险_3开源安全风险及其解决方法
  • 自助分析_为什么自助服务分析真的不是一回事
  • 错误录入 算法_如何使用验证错误率确定算法输出之间的关系
  • pytorch回归_PyTorch:用岭回归检查泰坦尼克号下沉
  • iris数据集 测试集_IRIS数据集的探索性数据分析

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

  1. 文本数据可视化_非结构化文本数据的分析和可视化

    文本数据可视化 Stuck behind the paywall? Read this article with my friend link here. 卡在收费墙后面? 在这里与我的朋友链接阅读本 ...

  2. 利用python数据可视化_想用Python做数据可视化?先迈过这个“坎”

    文丨Chris Moffitt 编译丨姜瑞琪 触脉咨询数据分析师 用过python的人都会面临一个问题,尤其是初学者:我应该选哪个来实现数据可视化? 面对众多的选项,要弄清楚什么时候使用哪个的问题没那 ...

  3. python 金融可视化_用 Python 进行金融数据可视化

    Python量化的关键是金融数据可视化,不管是传统的K线图,仍是如今的策略分析,都须要大量的可视化图表.具体到编程代码,就是使用Python绘图模块库绘图,好比传统的Python绘图模块库有Matpl ...

  4. python四维数据可视化_如何使用python进行数据可视化?

    使用包matplotlib包 导入语句: import matplotlib.pyplot as plt 散点图 折线图 帮助: 颜色线型点 一张画板绘制多张图 添加文本: 找到配置文件: 如何使用p ...

  5. keras时间序列数据预测_使用Keras的时间序列数据中的异常检测

    keras时间序列数据预测 Anomaly Detection in time series data provides e-commerce companies, finances the insi ...

  6. 什么事数据科学_如果您想进入数据科学,则必须知道的7件事

    什么事数据科学 No way. No freaking way to enter data science any time soon-That is exactly what I thought a ...

  7. seaborn添加数据标签_常见Seaborn图的数据标签快速指南

    seaborn添加数据标签 In the course of my data exploration adventures, I find myself looking at such plots ( ...

  8. 数据多重共线性_多重共线性对您的数据科学项目的影响比您所知道的要多

    数据多重共线性 Multicollinearity is likely far down on a mental list of things to check for, if it is on a ...

  9. 业务编排可视化_微服务设计-服务组合和可视化编排思考

    今天再重新整理下我对服务组合和服务可视化编排的一些思考. 从整个服务分层的角度来说,微服务最底层首先提供的是原子服务,再朝上则可以提供更加粗颗粒度的组合服务能力. 为何要进行服务组合和编排? 简单来说 ...

最新文章

  1. jre,jdk,jvm的关系
  2. Arcgis10.3在添加XY数据时出现问题
  3. wireshark捕获不到东西_好书分享——Wireshark从入门到精通
  4. Java 8 CompletableFuture 浅入
  5. 报错:selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This versio
  6. C#码农的大数据之路 - 使用C#编写MR作业
  7. Linux之Ubuntu安装搜狗输入法
  8. 天融信安全接入客户端_天融信提示您警惕物联网设备Ripple20漏洞风险
  9. maven 学习---Maven本地资源库
  10. 【吊炸天】TensorFlow什么的都弱爆了,强者只用Numpy搭建神经网络
  11. dajngo3,vue3前端项目搭建,vue项目结构的介绍
  12. 问题三十六:ray tracing中的Inverse Mapping(3)——圆盘Inverse Mapping
  13. 用C#实现***程序
  14. gtest -UT测试框架
  15. 谷歌开发者大会召开 地图服务成亮点
  16. 记一次华为交换机冲突问题
  17. 在高分辨率或者扩展屏下微信截图出现放大问题的解决
  18. 2021中国5G网络创新论坛议程重磅发布!会议亮点提前看,观众报名进入倒计时!...
  19. android 监听耳机插拔
  20. python3图片处理(笔记)

热门文章

  1. C语言实现的简单的线程池
  2. c++类对象的创建方式
  3. Windows 7 64位系统上搭建Hadoop伪分布式环境(很详细)
  4. [Swift]LeetCode884. 两句话中的不常见单词 | Uncommon Words from Two Sentences
  5. Java面向对象(二)
  6. LintCode 16. 带重复元素的排列
  7. Js实现div随鼠标移动的方法
  8. 算法专题 普及组【2008】三3 C++版
  9. mysqldump造成Buffer Pool污染的研究 [转]
  10. python pandas serie简介及基本使用