使用plotly能创建出色的交互式图 Plotly具有三个重要功能:
· 悬停:将鼠标悬停在图表上时,将弹出注释
· 交互性:无需任何其他设置即可使图表互动(例如,穿越时空的旅程)
· 漂亮的地理空间图:Plotly具有一些内置的基本地图绘制功能,但是另外,可以使用mapbox集成来生成惊人的图表。
点图我们通过运行fig = x。(PARAMS)然后调用fig.show()来调用绘图:
fig = px.scatter( data_frame=data[data['Year'] == 2018], x="Log GDP per capita", y="Life Ladder", size="Gapminder Population", color="Continent", hover_name="Country name", size_max=60)fig.show()
Plotly scatter plot, plotting Log GDP per capita against Life Ladder, where color indicates continent and size of the marker the population
散点图-漫步时光fig = px.scatter( data_frame=data, x="Log GDP per capita", y="Life Ladder", animation_frame="Year", animation_group="Country name", size="Gapminder Population", color="Continent", hover_name="Country name", facet_col="Continent", size_max=45, category_orders={'Year':list(range(2007,2019))} )fig.show()
Visualization of how the plotted data changes over the years
并行类别-一种可视化类别的有趣方式fig = px.bar( data, x="Continent", y="Gapminder Population", color="Mean Log GDP per capita", barmode="stack", facet_col="Year", category_orders={"Year": range(2007,2019)}, hover_name='Country name', hover_data=[ "Mean Log GDP per capita", "Gapminder Population", "Life Ladder" ])fig.show()
Seems like not all countries with high life expectations are happy!
条形图—交互式过滤器的示例fig = px.bar( data, x="Continent", y="Gapminder Population", color="Mean Log GDP per capita", barmode="stack", facet_col="Year", category_orders={"Year": range(2007,2019)}, hover_name='Country name', hover_data=[ "Mean Log GDP per capita", "Gapminder Population", "Life Ladder" ])fig.show()
Filtering a bar chart is easy. Not surprisingly, South Korea is among the wealthy countries in Asia.
Choropleth plot-幸福如何随着时间而变化fig = px.choropleth( data, locations="ISO3", color="Life Ladder", hover_name="Country name", animation_frame="Year")fig.show()
Map visualization of how happiness evolves over the years. Syria and Afghanistan are at the very end of the Life Ladder range (unsurprisingly)
结束语在本文中,我们学习了如何成为真正的Python可视化高手,了解了如何在快速探索方面提高效率,以及在再次召开董事会会议时如何创建更精美的图表。 还有交互式地图,这在绘制地理空间数据时特别有用哦。
本文翻译自Fabian Bosler的文章《Learn how to create beautiful and insightful charts with Python — the Quick, the Pretty, and the Awesome》 参考
https://towardsdatascience.com/plotting-with-python-c2561b8c0f1f)