天天看點

python動态互動圖表_使用python來繪制漂亮的圖表:出色的互動plotly篇!

我們最後來講python另外一個非常出色的可視化工具,使用plotly建立出色的互動式圖,最後,不再需要Matplotlib!

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()

python動态互動圖表_使用python來繪制漂亮的圖表:出色的互動plotly篇!

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()

python動态互動圖表_使用python來繪制漂亮的圖表:出色的互動plotly篇!

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()

python動态互動圖表_使用python來繪制漂亮的圖表:出色的互動plotly篇!

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()

python動态互動圖表_使用python來繪制漂亮的圖表:出色的互動plotly篇!

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)

完 謝謝觀看