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,一經查實,立即刪除!