Python中的 plotly.express.line_3d()函数
Python的 Plotly 库对于数据可视化和简单轻松地理解数据非常有用。 Plotly 图形对象是一个易于使用的高级界面。
plotly.express.line_3d()函数
此函数用于创建 3D 线图,并可与 pandas 数据框一起使用。每一行数据框都由折线图中 3D 空间中的符号标记表示。
Syntax: plotly.express.line_3d(data_frame=None, x=None, y=None, z=None, color=None, line_dash=None, text=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.
x, y, z: This parameters is either a name of a column in data_frame, or a pandas Series or array_like object. Values from this column or array_like are used to position marks along the x, y and z axis in cartesian coordinates respectively.
color: This parameters assign color to marks.
line_dash: This parameter is used to assign dash-patterns to lines.
line_group: This parameter is used to group rows of data_frame into lines.
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.
示例 1:
Python3
import plotly.express as px
df = px.data.tips()
plot = px.line_3d(df, x = 'time',
y = 'day',
z = 'sex')
plot.show()
Python3
import plotly.express as px
df = px.data.tips()
plot = px.line_3d(df, x = 'time',
y = 'day',
z = 'sex',
color = 'time')
plot.show()
Python3
# Python program to demonstrate scatter
# plot
import plotly.express as px
df = px.data.tips()
plot = px.line_3d(df, x = 'day',
y = 'total_bill',
z = 'sex',
color = 'time',
line_group = 'sex')
plot.show()
输出:
示例 2:
Python3
import plotly.express as px
df = px.data.tips()
plot = px.line_3d(df, x = 'time',
y = 'day',
z = 'sex',
color = 'time')
plot.show()
输出:
示例 3:
Python3
# Python program to demonstrate scatter
# plot
import plotly.express as px
df = px.data.tips()
plot = px.line_3d(df, x = 'day',
y = 'total_bill',
z = 'sex',
color = 'time',
line_group = 'sex')
plot.show()
输出: