Python中的 plotly.express.line_ternary()函数
Python的 Plotly 库对于数据可视化和简单轻松地理解数据非常有用。 Plotly 图形对象是一个易于使用的高级界面。
plotly.express.line_ternary()
此方法用于创建三元线图。三元线图用于描绘等边三角形上三个变量的比率。
Syntax: plotly.express.line_ternary(data_frame=None, a=None, b=None, c=None, color=None, line_dash=None, line_group=None, hover_name=None, hover_data=None, title=None, template=None, width=None, height=None)
Parameters:
data_frame: DataFrame or array-like or dict needs to be passed for column names.
a, b, c: These parameters are either a name of a column in data_frame, or a pandas Series or array_like object. These are used to position marks along the a, b, and c axis in ternary coordinates respectively.
color: This parameters assign color to marks.
hover_name: Values from this column or array_like appear in bold in the hover tooltip.
hover_data: This parameter is used to appear in the hover tooltip or tuples with a bool or formatting string as first element, and list-like data to appear in hover as second element Values from these columns appear as extra data in the hover tooltip.
title: The title of the figure.
width: Set the width of the figure.
height: Set the height of the figure.
示例 1:
Python3
import plotly.express as px
df = px.data.iris()
plot = px.line_ternary(df, a = 'sepal_width',
b = 'sepal_length',
c = 'petal_width')
plot.show()
Python3
import plotly.express as px
df = px.data.iris()
plot = px.line_ternary(df, a = 'sepal_width',
b = 'sepal_length',
c = 'petal_width',
color = 'species',
line_group = 'species')
plot.show()
输出:
示例 2:使用颜色和 line_group 参数
Python3
import plotly.express as px
df = px.data.iris()
plot = px.line_ternary(df, a = 'sepal_width',
b = 'sepal_length',
c = 'petal_width',
color = 'species',
line_group = 'species')
plot.show()
输出: