plotly python_使用Plotly for Python时的基本思路

plotly python

I recently worked with Plotly for data visualization on predicted outputs coming from a Machine Learning Model.

我最近与Plotly合作,对来自机器学习模型的预测输出进行数据可视化。

The documentation I referred to : https://plotly.com/python/

我提到的文档: https : //plotly.com/python/

Here are few “google searches” I personally did while I was working on it:

以下是我在进行搜索时亲自进行的“ google搜索”:

Question : Which data viz library should I choose for interactive plots?Answer : Matplotlib, Seaborn, Plotly, Altair, and Bokeh were some of the answers. The reason I went with Plotly was because my project requirement was to get charts on a html page which is supported by Plotly. With Plotly, the charts are stored as .html files and can be zoomed in, zoomed out and also focused on a particular region.

问:我应该为交互式绘图选择哪个数据视图库?答案: Matplotlib,Seaborn,Plotly,Altair和Bokeh是其中的一些答案。 我选择Plotly的原因是因为我的项目要求是在Plotly支持的html页面上获取图表。 使用Plotly,可以将图表存储为.html文件,并且可以放大,缩小并且还可以将焦点放在特定区域上。

Question: Plotly Express or Plotly Graph Objects Answer : I started with Plotly Express but ended up using Plotly Graph Objects for the very reason that it provided me a lot of modifications to my existing code. There were more number of attributes which could provide better cosmetic changes to the charts.

问题:Plotly Express或Plotly Graph对象 回答:我从Plotly Express开始,但最终由于使用Plotly Graph Objects而对我的现有代码进行了大量修改,因此最终使用了Plotly Graph Objects。 有更多的属性可以为图表提供更好的外观更改。

关于图形对象 (In terms of Plotly Graph Objects)

import plotly.graph_objs as go

将go导入plotly.graph_objs

Question: How do I show two columns from my data set against time?Answer : choose your “mode” as lines and lines + markers.mode = ‘lines’ , can be set when you add your trace.

问题:如何显示数据集中随时间变化的两列? 答案:选择“模式”作为线和线+标记。mode='lines',可以在添加迹线时设置。

fig = go.Figure()fig.add_trace(go.Scatter(x=data[‘time’],y=data[‘Values_x’],mode=‘lines’))fig.add_trace(go.Scatter(x=data[‘time’],y=data[‘Values_y’],mode=‘lines+markers’))

fig = go.Figure()fig.add_trace(go.Scatter(x = data ['time'],y = data ['Values_x'],mode ='lines'))fig.add_trace(go.Scatter(x = data ['time'],y = data ['Values_y'],mode ='lines + marks'))

Question: What else I can add in my go.Scatter() function to modify my data points?Answer: Other attributes which can be used to modify the plots can be name : name of the data point which is being plotted, string valueshowlegend : If the legend should be visible or not, Boolean value with True or Falsemarker_color : if your mode is lines+markers or just markers you can give a specific color to it, it accepts RGBA, RGB, HSL, or a name of the color in a string valueline_width : determines the width of the line in your plot, accepts an int value line_color : the color of the linefont : one can choose the font from the font family available in plotly.

问题:我还可以在go.Scatter()函数中添加哪些内容来修改数据点? 答:其他可用于修改图的属性可以是name :要绘制的数据点的名称,字符串值showlegend :如果图例不可见,则布尔值为True或False marker_color :如果您的模式是线条+标记或只是标记,您可以为其指定特定的颜色,可以接受RGBA,RGB,HSL或字符串值中的颜色名称line_width :确定绘图中线条的宽度,接受一个int值line_color :线条字体的颜色:可以从可用的字体家族中选择字体。

Question: Once I choose my font family, how do I choose the font color and its size?Answer: Many attributes in plotly have an option of specifying a dict and further writing a key value pair in it.

问:选择字体系列后,如何选择字体颜色和字体大小?答案 :plotly中的许多属性都可以选择指定dict并在其中进一步编写键值对。

font=dict(family=’Times New Roman’,size=16,color=’red’)

font = dict(family ='Times New Roman',size = 16,color ='red')

Question: How do I put a hover label on my plots?Answer : Hover labels are kind of boxes which are visible when you move your cursor to a specific data point. They help the user in understanding the value and other details in your chart.

问:如何在图形上放置一个悬停标签?答案:悬停标签是将光标移到特定数据点时可见的一种框。 它们帮助用户了解图表中的值和其他详细信息。

hoverlabel=dict(bgcolor=’lightblue’,font=dict(family=’Times New Roman’,size=16),bordercolor=’black’),hovertemplate=’Booth Humidity<br>Probability: %{y}’)

hoverlabel = dict(bgcolor ='lightblue',font = dict(family ='Times New Roman',size = 16),bordercolor ='black'),hovertemplate ='Booth Humidity <br> Probability:%{y}')

bgcolor is the back ground color of the hover boxhovertemplate will contain basic html tags, it can be altered according to the style one wants to keep.

bgcolor是悬停框的背景hovertemplate将包含基本的html标签,可以根据您想要保留的样式进行更改。

Question: How do I make subplots in plotly?Answer: There are various kinds of subplots which we can make on plotly by specifying the number of rows and columns.

问题:我如何进行子图绘制? 答:通过指定行数和列数,可以在图上进行多种子图绘制。

fig.make_subplots(rows=3,column=1,vertical_spacing=0.5,horizontal_spacing=0.5)

fig.make_subplots(行= 3,列= 1,垂直间距= 0.5,水平间距= 0.5)

This will give you 3 subplots stacked together. It can be varied accordingly. Vertical spacing indicates the distance between the columns of the subplots specified whereas the Horizontal Spacing is between two rows of the subplots.

这将使您将3个子图堆叠在一起。 它可以相应地变化。 垂直间距表示指定的子图的各列之间的距离,而水平间距表示子图的两行之间。

Simply specify row and column number in each go.Scatter function. This way you can also keep multiple data points in the same subplot. (i.e two or more go.Scatter can have same row number and column number)

只需在每个go.Scatter函数中指定行号和列号。 这样,您还可以将多个数据点保留在同一子图中。 (即两个或多个go.Scatter可以具有相同的行号和列号)

Question: How do I make one subplot to be larger in size than my other two subplots?Answer: There is a very useful parameter called “specs” which is basically a 2D list inside the make_subplots() function where one can specify the colspan, rowspan or None. None indicates that no subplot will be drawn in that dimension and hence that is where your larger sized subplot goes.

问题:如何使一个子图的尺寸大于其他两个子图的尺寸? 答:有一个非常有用的参数称为“ specs” ,它基本上是make_subplots()函数中的2D列表,可以在其中指定colspan,rowspan或None。 None表示不会在该维度上绘制子图,因此这是您较大尺寸的子图所在的位置。

Question: Can I make a subplot with common axis?Answer: Plotly has a provision of making subplots with shared (common) xaxis and yaxis. shared_xaxes or shared_yaxes has to be set to true in the make_subplots() function

问题:我可以制作一个具有公共轴的子图吗? 答: Plotly提供了使用共享(公用)xaxis和yaxis制作子图的条件。 必须在make_subplots()函数中将shared_xaxes或shared_yaxes设置为true

Question: How do I give different xaxis title or yaxis title to each subplot?Answer: you can specify the axis title with the subplot number in the update_layout() function.

问题:如何给每个子图赋予不同的xaxis标题或yaxis标题? 答:您可以在update_layout()函数中用子图号指定轴标题。

Example- for subplot in the row 2 has the yaxis titled as yaxis2_title

示例-第2行中的子图的yaxis标题为yaxis2_title

Question: What is update_layout and what all attributes it holds?Answer: update_layout is the overall function to make the plot look presentable. One can specify the following in it:height : Height of the chartwidth : Width of the charttitle: The overall title of your chartshowgrid: the horizontal and vertical gridlines present in your chart plot_bgcolor: the color inside the plot paper_bgcolor: the color where the plot is present

问题:什么是update_layout?它具有什么所有属性? 答: update_layout是使绘图看起来更美观的整体功能。 一个可以指定在它下面的: 高度:图表宽度的高度图表标题的宽度图表showgrid的整体标题水平和垂直网格线存在于图表plot_bgcolor:颜色的情节paper_bgcolor颜色情节所在的地方

Question: Does Plotly have individual functions to update xaxis and yaxis?Answer: It indeed does, update_xaxes and update_yaxes has attributes like showgrid, title_font, etc which can be modified as per the requirements.

问题:Plotly是否有单独的功能来更新xaxis和yaxis? 答:的确如此, update_xaxes和update_yaxes具有诸如showgrid,title_font等属性,可以根据要求进行修改。

Question: Can we give names to each subplot?Answers: Each subplot can be given a title by the attribute subplot_titles present in the make_subplots() function.

问题:我们可以给每个子图命名吗? 答案:每个子图都可以通过make_subplots()函数中存在的属性subplot_titles来获得标题。

I have also used the other functionalities like a Range Slider and buttons in Plotly which I will be discussing in my next article very soon!

我还使用了其他功能,例如范围滑块和 Plotly中的按钮 ,这些功能我将在下一篇文章中很快讨论!

This was the first time I touched upon Data Visualization using Python. I have also written few other articles on Data Viz using tools like PowerBI which can be found here

这是我第一次使用Python进行数据可视化。 我还使用PowerBI之类的工具在Data Viz上写了其他文章,可以在这里找到

I have also developed an alerting system app using PowerApps and written an article about an awesome function I used there to integrate it with my PowerBI reports. Do check that out too here.

我还使用PowerApps开发了一个警报系统应用程序,并写了一篇文章,介绍了我在其中使用过的强大功能将其与PowerBI报告集成在一起。 这里也要检查一下 。

Let me know if you have any queries or suggestions regarding this by commenting below or reach me out on Twitter for any fun discussions revolving around Data Viz or Pandas! :)

如果您对此有任何疑问或建议,请在下面评论中告诉我,或者在Twitter上与我联系,以获取有关Data Viz或Pandas的有趣讨论! :)

翻译自: https://medium.com/analytics-vidhya/basic-thoughts-while-working-with-plotly-for-python-3721d160303c

plotly python

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

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

相关文章

转发:毕业前的赠言

1、找一份真正感兴趣的工作。 “一个人如果有两个爱好&#xff0c;并且把其中一个变成自己的工作&#xff0c;那会是一件非常幸福的事情。那么另外一个爱好用来做什么&#xff1f;打发时间啦。所以&#xff0c;第二个兴趣非常重要&#xff0c;在你无聊寂寞的时候越发显得它…

Python模块之hashlib:提供hash算法

算法介绍 Python的hashlib提供了常见的摘要算法&#xff0c;如MD5&#xff0c;SHA1等等。 什么是摘要算法呢&#xff1f;摘要算法又称哈希算法、散列算法。它通过一个函数&#xff0c;把任意长度的数据转换为一个长度固定的数据串&#xff08;通常用16进制的字符串表示&#xf…

css flexbox模型_完整CSS课程-包括flexbox和CSS网格

css flexbox模型Learn CSS in this complete 83-part course for beginners. Cascading Style Sheets (CSS) tell the browser how to display the text and other content that you write in HTML.在这本由83部分组成的完整课程中&#xff0c;为初学者学习CSS。 级联样式表(CS…

leetcode 830. 较大分组的位置

在一个由小写字母构成的字符串 s 中&#xff0c;包含由一些连续的相同字符所构成的分组。 例如&#xff0c;在字符串 s “abbxxxxzyy” 中&#xff0c;就含有 “a”, “bb”, “xxxx”, “z” 和 “yy” 这样的一些分组。 分组可以用区间 [start, end] 表示&#xff0c;其中…

php 匹配图片路径_php正则匹配图片路径原理与方法

下面我来给大家介绍在php正则匹配图片路径原理与实现方法&#xff0c;有需要了解的朋友可进入参考参考。提取src里面的图片地址还不足够&#xff0c;因为不能保证那个地址一定是绝对地址&#xff0c;完全的地址&#xff0c;如果那是相对的呢&#xff1f;如果地址诸如&#xff1…

java项目经验行业_行业研究以及如何炫耀您的项目

java项目经验行业苹果 | GOOGLE | 现货 | 其他 (APPLE | GOOGLE | SPOTIFY | OTHERS) Editor’s note: The Towards Data Science podcast’s “Climbing the Data Science Ladder” series is hosted by Jeremie Harris. Jeremie helps run a data science mentorship startup…

MongoDB教程-使用Node.js从头开始CRUD应用

In this MongoDB Tutorial from NoobCoder, you will learn how to use MongoDB to create a complete Todo CRUD Application. This project uses MongoDB, Node.js, Express.js, jQuery, Bootstrap, and the Fetch API.在NoobCoder的MongoDB教程中&#xff0c;您将学习如何使…

leetcode 399. 除法求值(bfs)

给你一个变量对数组 equations 和一个实数值数组 values 作为已知条件&#xff0c;其中 equations[i] [Ai, Bi] 和 values[i] 共同表示等式 Ai / Bi values[i] 。每个 Ai 或 Bi 是一个表示单个变量的字符串。 另有一些以数组 queries 表示的问题&#xff0c;其中 queries[j]…

【0718作业】收集和整理面向对象的六大设计原则

面向对象的六大设计原则 &#xff08;1&#xff09;单一职责原则——SRP &#xff08;2&#xff09;开闭原则——OCP &#xff08;3&#xff09;里式替换原则——LSP &#xff08;4&#xff09;依赖倒置原则——DIP &#xff08;5&#xff09;接口隔离原则——ISP &#xff08;…

数据科学 python_适用于数据科学的Python vs(和)R

数据科学 pythonChoosing the right programming language when taking on a new project is perhaps one of the most daunting decisions programmers often make.在进行新项目时选择正确的编程语言可能是程序员经常做出的最艰巨的决定之一。 Python and R are no doubt amon…

如何进行有效的需求调研

一、什么是需求调研&#xff1f;需求调研对于一个应用软件开发来说&#xff0c;是一个系统开发的开始阶段&#xff0c;它的输出“软件需求分析报告”是设计阶段的输入&#xff0c;需求调研的质量对于一个应用软件来说&#xff0c;是一个极其重要的阶段&#xff0c;它的质量在一…

java中直角三角形第三条边,Java编程,根据输入三角形的三个边边长,程序能判断三角形类型为:等边、等腰、斜角、直角三角形,求代码...

private static Scanner sc;private static int edge[] new int[3];public static void main(String[] args) {System.out.println("请输入三角形的三条边");sc new Scanner(System.in);input();}public static void input() {int index 0;//数组下标while (sc.ha…

react中使用构建缓存_使用React和Netlify从头开始构建电子商务网站

react中使用构建缓存In this step-by-step, 6-hour tutorial from Coding Addict, you will learn to build an e-commerce site from scratch using React and create-react-app.在这个Coding Addict的分步&#xff0c;为时6小时的教程中&#xff0c;您将学习使用React和creat…

Django+Vue前后端分离项目的部署

部署静态文件&#xff1a; 静态文件有两种方式 1&#xff1a;通过django路由访问 2&#xff1a;通过nginx直接访问 方式1&#xff1a; 需要在根目录的URL文件中增加 url(r^$, TemplateView.as_view(template_name"index.html")),作为入口&#xff0c;在setting中更改…

leetcode 547. 省份数量(bfs)

有 n 个城市&#xff0c;其中一些彼此相连&#xff0c;另一些没有相连。如果城市 a 与城市 b 直接相连&#xff0c;且城市 b 与城市 c 直接相连&#xff0c;那么城市 a 与城市 c 间接相连。 省份 是一组直接或间接相连的城市&#xff0c;组内不含其他没有相连的城市。 给你一…

r怎么对两组数据统计检验_数据科学中最常用的统计检验是什么

r怎么对两组数据统计检验Business analytics and data science is a convergence of many fields of expertise. Professionals form multiple domains and educational backgrounds are joining the analytics industry in the pursuit of becoming data scientists.业务分析和…

win10专业版激活(cmd方式)

转载于:https://www.cnblogs.com/bug-baba/p/11225322.html

mit景观生成技术_永远不会再为工作感到不知所措:如何使用MIT技术

mit景观生成技术by Sihui Huang黄思慧 永远不会再为工作感到不知所措&#xff1a;如何使用MIT技术 (Never feel overwhelmed at work again: how to use the M.I.T. technique) Have you ever felt exhausted after a day at work? At the end of a busy day, you couldn’t …

leetcode 189. 旋转数组

给定一个数组&#xff0c;将数组中的元素向右移动 k 个位置&#xff0c;其中 k 是非负数。 示例 1: 输入: [1,2,3,4,5,6,7] 和 k 3 输出: [5,6,7,1,2,3,4] 解释: 向右旋转 1 步: [7,1,2,3,4,5,6] 向右旋转 2 步: [6,7,1,2,3,4,5] 向右旋转 3 步: [5,6,7,1,2,3,4] 代码 cla…

aws ec2 php,如何使用php aws sdk启动和停止ec2实例

以下是从定义的AMI启动计算机的基本示例&#xff1a;$image_id ami-3d4ff254; //Ubuntu 12.04$min 1; //the minimum number of instances to start$max 1; //the maximum number of instances to start$options array(SecurityGroupId > default, //replace with your …