在Python中使用 plotly 填充面积图
Plotly 是一个Python库,用于设计图形,尤其是交互式图形。它可以绘制各种图形和图表,如直方图、条形图、箱线图、散布图等等。它主要用于数据分析和财务分析。 plotly 是一个交互式可视化库。
填充面积图
填充区域图是一种易于使用的高级表达方式,可完成各种类型的数据并生成易于样式化的图形。每个填充区域与 line_group 参数给出的列的一个值相协调。填充区域图最常用于显示趋势,而不是传达特定值。面积图的两种流行变体是:分组面积图和堆积面积图。
Syntax: plotly.express.area(data_frame=None, x=None, y=None, line_group=None, color=None, hover_name=None, hover_data=None, custom_data=None, text=None, facet_row=None, facet_col=None, facet_col_wrap=0, animation_frame=None, animation_group=None, category_orders={}, labels={}, color_discrete_sequence=None, color_discrete_map={}, orientation=None, groupnorm=None, log_x=False, log_y=False, range_x=None, range_y=None, line_shape=None, title=None, template=None, width=None, height=None)
Parameters:
data_frame: This argument needs to be passed for column names (and not keyword names) to be used. Array-like and dict are transformed internally to a pandas DataFrame.
x, y: 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 and y axis in cartesian coordinates.
color: 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 assign color to marks.
示例 1:
Python3
import plotly.express as px
df = px.data.iris()
fig = px.area(df, x="sepal_width", y="sepal_length",
color="species",
hover_data=['petal_width'],)
fig.show()
Python3
import plotly.express as px
import numpy as np
# creating random data through randomint
# function of numpy.random
np.random.seed(42)
random_x= np.random.randint(1,101,100)
random_y= np.random.randint(1,101,100)
fig = px.area(x = random_x, y = random_y)
fig.show()
Python3
import plotly.express as px
df = px.data.tips()
fig = px.area(df, x ='total_bill', y = 'day')
fig.show()
Python3
import plotly.express as px
df = px.data.tips()
fig = px.area(df, x ='time', y = 'day',
color="total_bill")
fig.show()
输出:
示例 2:
Python3
import plotly.express as px
import numpy as np
# creating random data through randomint
# function of numpy.random
np.random.seed(42)
random_x= np.random.randint(1,101,100)
random_y= np.random.randint(1,101,100)
fig = px.area(x = random_x, y = random_y)
fig.show()
输出:
示例 3:
Python3
import plotly.express as px
df = px.data.tips()
fig = px.area(df, x ='total_bill', y = 'day')
fig.show()
输出:
示例 4:
Python3
import plotly.express as px
df = px.data.tips()
fig = px.area(df, x ='time', y = 'day',
color="total_bill")
fig.show()
输出: