最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python可視化plotly?圖例(legend)設(shè)置

 更新時間:2022年02月17日 14:27:36   作者:Eloik  
這篇文章主要介紹了python可視化plotly?圖例(legend)設(shè)置,主要介紹了關(guān)于python?的legend圖例,參數(shù)使用說明,具有很好的參考價值,希望對大家有所幫助,需要的朋友可以參考下賣你具體內(nèi)容

一、圖例(legend)

import plotly.io as pio
import plotly.express as px
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import pandas as pd
import numpy as np

# 設(shè)置plotly默認(rèn)主題
pio.templates.default = 'plotly_white'

# 設(shè)置pandas打印時顯示所有列
pd.set_option('display.max_columns', None)

二、update_layout(legend={}) 相關(guān)參數(shù)及示例

官方文檔:https://plotly.com/python/reference/layout/#layout-showlegend

官方示例:https://plotly.com/python/legend/

  • showlegend:是否顯示圖例,以下任一種情況發(fā)生時,該參數(shù)默認(rèn)值為 True:1. 兩個及兩個以上的 trace 2. 有餅圖3. 有一個 trace 顯式指定 showlegend=True
  • legend:圖例相關(guān)設(shè)置,字典類型,可取屬性如下:
    • bgcolor:設(shè)置圖例的背景顏色
    • bordercolor:設(shè)置圖例邊框的顏色
    • borderwidth:設(shè)置圖例邊框的寬度
    • font:設(shè)置圖例條目的文本字體,字典類型,可取屬性如下:
    • color:字體顏色
    • family:字體,字符串,可以為 Arial、Balto、Courier New、Droid Sans、Droid Serif、Droid Sans Mono、Gravitas One、Old Standard TT、Open Sans、Overpass、PT Sans Narrow、Raleway、Times New Roman
    • size:字體大小
  • orientation:設(shè)置圖例的方向。'v'(默認(rèn)值)表示豎直顯示圖例、'h'表示水平顯示圖例
  • title:設(shè)置圖例的標(biāo)題,字典類型,可取屬性如下:

font:設(shè)置圖例條目的文本字體,字典類型,可取屬性如下:

  • color:字體顏色
  • family:字體,字符串,可以為 Arial、Balto、Courier New、Droid Sans、Droid Serif、Droid Sans Mono、Gravitas One、Old Standard TT、Open Sans、Overpass、PT Sans Narrow、Raleway、Times New Roman
  • size:字體大小

side:設(shè)置圖例標(biāo)題相對于條目的位置。當(dāng) orientation='v' 時默認(rèn)為 'top'、當(dāng) orientation='h'時默認(rèn)為 'left'、當(dāng)為 'top left'時可用于擴展圖例的面積
text:設(shè)置圖例標(biāo)題

  • grouptitlefont:設(shè)置圖例組名的文本字體,字典類型,可取屬性如下:
    • color:字體顏色
    • family:字體,字符串,可以為 Arial、Balto、Courier New、Droid Sans、Droid Serif、Droid Sans Mono、Gravitas One、Old Standard TT、Open Sans、Overpass、PT Sans Narrow、Raleway、Times New Roman
    • size:字體大小
  • itemsizing:設(shè)置圖例條目的符號是否跟其 ‘trace’ 有關(guān),如果為 'constant',則所有條目的符號大小一致。
    • 可取 'trace'、 'constant'
  • itemwidth:設(shè)置條目的寬度(除 title 以外的部分)
    • 大于等于30的浮點數(shù),默認(rèn)值為30
  • tracegroupgap:設(shè)置圖例組之間的間隔
    • 大于等于0的浮點數(shù),默認(rèn)值為10

traceorder:設(shè)置圖例條目的順序。如果為 'normal',條目將從上到下按照輸入數(shù)據(jù)的順序排列;如果為 'reversed',則按照輸入數(shù)據(jù)的逆序排列;如果為 'grouped',條目按照組順序顯示(如果 trace 中的legendgroup 設(shè)定了);如果為 'grouped+reversed',則與 'grouped'的順序相反
valign:設(shè)置條目符號和對應(yīng)文本的豎直對齊方式。
可取 'middle'(默認(rèn)值)、'top'、'bottom'

df = px.data.gapminder().query("year==2007")
fig = px.scatter(df, x="gdpPercap", y="lifeExp", color="continent",
? ? size="pop", size_max=45, log_x=True)

fig.update_layout(legend=dict(
? ? yanchor="top",
? ? y=0.99,
? ? xanchor="left",
? ? x=0.01
))

fig.write_image('../pic/legend_1.png', scale=2)
fig.show()

df = px.data.gapminder().query("year==2007")
fig = px.scatter(df, x="gdpPercap", y="lifeExp", color="continent",
? ? size="pop", size_max=45, log_x=True)

fig.update_layout(legend=dict(
? ? orientation="h",
? ? yanchor="bottom",
? ? y=1.02,
? ? xanchor="center",
? ? x=0.5,
? ? title_text=''
))

fig.write_image('../pic/legend_2.png', scale=2)
fig.show()

df = px.data.gapminder().query("year==2007")
fig = px.scatter(df, x="gdpPercap", y="lifeExp", color="continent",
? ? size="pop", size_max=45, log_x=True)


fig.update_layout(
? ? legend=dict(
? ? ? ? x=0,
? ? ? ? y=1,
? ? ? ? traceorder="reversed",
? ? ? ? title_font_family="Times New Roman",
? ? ? ? font=dict(
? ? ? ? ? ? family="Courier",
? ? ? ? ? ? size=12,
? ? ? ? ? ? color="black"
? ? ? ? ),
? ? ? ? bgcolor="LightSteelBlue",
? ? ? ? bordercolor="Black",
? ? ? ? borderwidth=2
? ? )
)

fig.write_image('../pic/legend_3.png', scale=2)
fig.show()

fig = go.Figure()

# 使用 name 參數(shù)指定條目文本,legendrank 指定順序
fig.add_trace(go.Bar(name="fourth", x=["a", "b"], y=[2,1], legendrank=4))
fig.add_trace(go.Bar(name="second", x=["a", "b"], y=[2,1], legendrank=2))
fig.add_trace(go.Bar(name="first", x=["a", "b"], y=[1,2], legendrank=1))
fig.add_trace(go.Bar(name="third", x=["a", "b"], y=[1,2], legendrank=3))

fig.write_image('../pic/legend_4.png', scale=2)
fig.show()

fig = go.Figure()

fig.add_trace(go.Scatter(
? ? x=[1, 2, 3],
? ? y=[2, 1, 3],
? ? legendgroup="group", ?# this can be any string, not just "group"
? ? legendgrouptitle_text="First Group Title",
? ? name="first legend group",
? ? mode="markers",
? ? marker=dict(color="Crimson", size=10)
))

fig.add_trace(go.Scatter(
? ? x=[1, 2, 3],
? ? y=[2, 2, 2],
? ? legendgroup="group",
? ? name="first legend group - average",
? ? mode="lines",
? ? line=dict(color="Crimson")
))

fig.add_trace(go.Scatter(
? ? x=[1, 2, 3],
? ? y=[4, 9, 2],
? ? legendgroup="group2",
? ? legendgrouptitle_text="Second Group Title",
? ? name="second legend group",
? ? mode="markers",
? ? marker=dict(color="MediumPurple", size=10)
))

fig.add_trace(go.Scatter(
? ? x=[1, 2, 3],
? ? y=[5, 5, 5],
? ? legendgroup="group2",
? ? name="second legend group - average",
? ? mode="lines",
? ? line=dict(color="MediumPurple")
))

fig.update_layout(title="Try Clicking on the Legend Items!")

fig.write_image('../pic/legend_5.png', scale=2)
fig.show()

fig = go.Figure()

fig.add_trace(go.Scatter(
? ? x=[1, 2, 3, 4, 5],
? ? y=[1, 2, 3, 4, 5],
))

fig.add_trace(go.Scatter(
? ? x=[1, 2, 3, 4, 5],
? ? y=[5, 4, 3, 2, 1],
? ? visible='legendonly'
))

fig.write_image('../pic/legend_6.png', scale=2)
fig.show()

fig = go.Figure()

fig.add_trace(go.Scatter(
? ? x=[1, 2, 3, 4, 5],
? ? y=[1, 2, 3, 4, 5],
? ? showlegend=False
))


fig.add_trace(go.Scatter(
? ? x=[1, 2, 3, 4, 5],
? ? y=[5, 4, 3, 2, 1],
))

fig.update_layout(showlegend=True)

fig.write_image('../pic/legend_7.png', scale=2)
fig.show()

fig = go.Figure()

fig.add_trace(go.Scatter(
? ? x=[1, 2, 3, 4, 5],
? ? y=[1, 2, 3, 4, 5],
? ? mode='markers',
? ? marker={'size':10}
))

fig.add_trace(go.Scatter(
? ? x=[1, 2, 3, 4, 5],
? ? y=[5, 4, 3, 2, 1],
? ? mode='markers',
? ? marker={'size':100}
))

fig.update_layout(legend= {'itemsizing': 'trace'})

fig.write_image('../pic/legend_8.png', scale=2)
fig.show()

到此這篇關(guān)于python可視化plotly 圖例(legend)設(shè)置的文章就介紹到這了,更多相關(guān)plotly 圖例(legend)設(shè)置內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

遂溪县| 永仁县| 信丰县| 临沭县| 兴文县| 永春县| 通河县| 阿拉善左旗| 信宜市| 大厂| 丽江市| 简阳市| 含山县| 宜良县| 鄂托克前旗| 德庆县| 大兴区| 泉州市| 巴彦淖尔市| 固镇县| 婺源县| 丽江市| 班戈县| 大方县| 苍梧县| 双流县| 文成县| 乌苏市| 西盟| 正镶白旗| 昌乐县| 新沂市| 郁南县| 肥城市| 烟台市| 丁青县| 开鲁县| 宝丰县| 大同县| 龙州县| 南城县|