Python Plotly 学习笔记3
plotly.express
访问数据集
import plotly.express as px
print(px.data.iris.__doc__)
px.data.iris().head()
输出:
scatter
df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species", marginal_y="rug", marginal_x="histogram")
fig.show()
marginal_x 和 x轴同方向:直方图
marginal_y 和 y轴同方向
import plotly.express as px
df = px.data.tips()
fig = px.scatter(df, x="total_bill", y="tip", color="size", facet_col="sex",
color_continuous_scale=px.colors.sequential.Viridis, render_mode="webgl")
fig.show()
动画效果
import plotly.express as px
df = px.data.gapminder()
fig = px.scatter(df, x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country",
size="pop", color="continent", hover_name="country", facet_col="continent",
log_x=True, size_max=45, range_x=[100,100000], range_y=[25,90])
fig.show()