可视化神器–Plotly Express

作者 : 开心源码 本文共3002个字,预计阅读时间需要8分钟 发布时间: 2022-05-12 共147人阅读

Plotly Express 是一个新的高级 Python 可视化库:它是 Plotly.py 的高级封装,它为复杂的图表提供了一个简单的语法。
用 pip install plotly_express 命令可以安装 Plotly Express。

import plotly_express as pxpx.scatter(gapminder2007, x='gdpPercap', y='lifeExp',color='continent',size='pop',size_max=60,hover_name='country')

px.scatter(gapminder2007, x='gdpPercap', y='lifeExp',color='continent',size='pop',size_max=60,hover_name='country',facet_col ='continent',log_x=True)

px.scatter(gapminder, x='gdpPercap', y='lifeExp',            color='continent', size='pop',            size_max=60, hover_name='country',          animation_frame='year', animation_group='country',          log_x=True, range_x=[10,100000],          range_y=[25,90], labels=dict(pop='Population', gdpPercap='GDP per Capita', lifeExp='Life Expectancy'))

px.choropleth(gapminder, locations='iso_alpha', color='lifeExp',             hover_name='country', animation_frame='year',             color_continuous_scale=px.colors.sequential.Plasma,             projection='natural earth')

iris = px.data.iris()px.scatter(iris, x='sepal_width', y='sepal_length',            color='species', marginal_y='histogram',          marginal_x='box', trendline='ols')

image.png

tips = px.data.tips()px.scatter(tips, x='total_bill', y='tip',facet_row='time',          facet_col='day',color='smoker',trendline='ols',          category_orders={'day':['Thur', 'Fri', 'Sat', 'Sun'], 'time':['Lunch', 'Dinner']})

px.parallel_coordinates(iris, color='species_id',                       color_continuous_scale=px.colors.diverging.Tealrose,                       color_continuous_midpoint=2)

px.parallel_categories(tips, color="size", color_continuous_scale=px.colors.sequential.Inferno)

px.density_contour(iris, x="sepal_width", y="sepal_length")

px.density_contour(iris, x="sepal_width", y="sepal_length", color="species")

px.histogram(tips, x="total_bill", color="smoker", facet_row="day", facet_col="time")

px.box(tips, y="tip", x="sex", color="smoker", facet_col="day", facet_row="time",        category_orders={"day": ["Thur", "Fri", "Sat", "Sun"], "time": ["Lunch", "Dinner"]})

px.violin(tips, y="tip", x="sex", color="smoker", facet_col="day", facet_row="time",         category_orders={"day": ["Thur", "Fri", "Sat", "Sun"], "time": ["Lunch", "Dinner"]})

election = px.data.election()px.scatter_ternary(election, a="Joly", b="Coderre", c="Bergeron", color="winner", size="total", hover_name="district",                   symbol="result",                    size_max=15, color_discrete_map = {"Joly": "blue", "Bergeron": "green", "Coderre":"red"}                  )

px.scatter_3d(election, x="Joly", y="Coderre", z="Bergeron", color="winner", size="total", hover_name="district",                  symbol="result", color_discrete_map = {"Joly": "blue", "Bergeron": "green", "Coderre":"red"})

px.bar_polar(wind, r="value", theta="direction", color="strength", template="plotly_dark",            color_discrete_sequence= px.colors.sequential.Plotly[-2::-1])

px.scatter_matrix(iris, dimensions=["sepal_width", "sepal_length", "petal_width", "petal_length"], color="species")

px.parallel_coordinates(iris, color='species_id', color_continuous_scale=['red','green', 'blue'])

import plotly_express as pxfig = px.scatter(px.data.iris(), x='sepal_width', y='sepal_length', color='species')import plotly.graph_objs as gofig.update(layout=dict(legend=dict(orientation='h',y=1.1,x=0.5),                      annotations=[go.layout.Annotation(text='this one is interesting', x=3.6, y=7.2)]))

说明
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是摆设,本站源码仅提供给会员学习使用!
7. 如遇到加密压缩包,请使用360解压,如遇到无法解压的请联系管理员
开心源码网 » 可视化神器–Plotly Express

发表回复