An warware: ƙara lakabin akan taswirar choropleth

A cikin 'yan shekarun nan, taswirar choropleth sun zama sananne sosai, yayin da suke ba da wakilci mai sauƙin fahimta na hadaddun bayanai a cikin tsari mai mahimmanci. Taswirar choropleth wani nau'in taswirar jigo ne inda wuraren ke da launi ko ƙima bisa darajar wani maɓalli na musamman. Ɗaya daga cikin ƙalubale wajen ƙirƙirar waɗannan taswirori shine buƙatar ƙara lakabi, wanda zai iya taimakawa masu amfani su fahimci bayanin da ake wakilta. A cikin wannan labarin, za mu bincika mafita don ƙara lakabi zuwa taswirar choropleth ta amfani da Python.

Ƙara tambari zuwa taswirar choropleth ta amfani da Python

Laburaren gama gari don ƙirƙirar taswirorin choropleth a Python shine GeoPandas, wanda ke ba masu amfani damar ƙirƙira da sarrafa bayanan geospatial. GeoPandas yana ƙara shahara pandas library ta hanyar samar da bayanan bayanan da aka tsara musamman don aiki tare da bayanan yanki. Don ƙara alamomi zuwa taswirar choropleth da aka ƙirƙira tare da GeoPandas, zaku iya amfani da matplotlib ɗakin karatu, ɗakin karatu na gani da aka yi amfani da shi sosai a cikin Python.

Jagorar mataki-mataki don ƙara lakabi zuwa taswirar choropleth a Python

A cikin wannan sashe, za mu yi tafiya ta hanyar ƙara alamomi zuwa taswirar choropleth ta amfani da Python da dakunan karatu na GeoPandas da matplotlib. Bi waɗannan matakan:

1. Na farko, shigo da dakunan karatu da ake bukata:

import geopandas as gpd
import matplotlib.pyplot as plt

2. Karanta siffar siffar wanda ya ƙunshi iyakokin yanki da kuke son amfani da su a cikin taswirar choropleth:

data = gpd.read_file('path/to/your/shapefile.shp')

3. Ƙirƙirar taswirar choropleth ta amfani da hanyar 'makirci' daga GeoPandas:

ax = data.plot(column='variable', cmap='coolwarm', legend=True)

Inda ''mai canzawa'' ke wakiltar ginshiƙi daga bayananku da kuke son wakilta a cikin taswirar choropleth, kuma ''coolwarm'' shine palette mai launi. Kuna iya tsara palette mai launi ta zaɓar wasu zaɓuɓɓuka daga tsarin launi na matplotlib.

4. Labara alamomi zuwa taswirar choropleth ta amfani da aikin `annotate' daga matplotlib:

for x, y, label in zip(data.geometry.centroid.x, data.geometry.centroid.y, data['variable']):
    ax.annotate(label, xy=(x, y), xytext=(x, y), color='black', fontsize=8)

Anan, muna maimaita ta hanyar centroid na kowane polygon a cikin GeoDataFrame kuma muna ƙara alamar (darajar ma'auni) a wannan matsayi.

5. Daga karshe, nuna taswirar choropleth tare da lakabi:

plt.show()

Fahimtar GeoPandas da matplotlib

  • GeoPandas: GeoPandas babban ɗakin karatu ne mai ƙarfi wanda ke yin aiki tare da bayanan geospatial a Python cikin sauƙi da inganci. Yana ba da ingantaccen tsarin bayanai da algorithms don aiki tare da bayanan sararin samaniya, gami da ikon karantawa da rubuta nau'ikan tsari daban-daban, aiwatar da ayyukan sararin samaniya, da samar da ci-gaba na firikwensin sararin samaniya.
  • matplotlib: matplotlib yana ɗaya daga cikin shahararrun ɗakunan karatu na gani na bayanai a Python, yana ba da zaɓuɓɓukan ƙirƙira iri-iri. Zaɓuɓɓukan gyare-gyarenta masu yawa suna ba masu amfani damar ƙirƙirar hadaddun abubuwan gani da suka dace sosai. A cikin wannan labarin, mun yi amfani da matplotlib a haɗe tare da GeoPandas don ƙara tambari zuwa taswirar choropleth.

A ƙarshe, ƙara alamomi zuwa taswirar choropleth ta amfani da Python ana iya samun su tare da taimakon GeoPandas da ɗakunan karatu na matplotlib. Tare da waɗannan kayan aikin, zaku iya ƙirƙirar cikakkun bayanai da bayyanannun bayanan gani na hadaddun bayanai, yana sauƙaƙa wa masu amfani don fahimta da fassara bayanan da aka gabatar.

Shafi posts:

Leave a Comment