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.pswp.cn/news/392370.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/392370.shtml
英文地址,請注明出處:http://en.pswp.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 …