Comments (7)
Hi Joseph, thanks for your interest in my library! I had intended for the mkdocs to cover the usage of pycart, but coming back to this after a year away I can see it isn't as clear as I had thought 😄
All the code used to generate images for the associated dissertation can be found in main.py; this might provide a little more insight into how I had used it with a real dataset, but I understand that it's not the most readable.
Do you have a particular dataset in mind for displaying on the graph gallery, or what you have in mind for the article in general? I'd be more than happy to take a look and see if I can come up with a more targeted example.
from ecmm428-pycart.
for example I have this dataset about co2 per capita across europe that I'd like to plot:
import geopandas as gpd
data = gpd.read_file('https://raw.githubusercontent.com/JosephBARBIERDARNAL/misc-dataviz/main/country-co2/data.geojson')
As for the article, ideally I'd probably write 2 or 3 to go from the simplest use case to an advanced 'real life' chart. Probably something like this
Do you have an idea of the best way to create the cartogram? Also, the posts will probably describe what cartograms are in general
from ecmm428-pycart.
No worries, this data is actually already formatted perfectly for pycart. I've written a really basic script below that takes your data and plots a simple dorling cartogram (where countries are represented as circles of size proportional to their value field, in this case Co2 per Capita).
In this case, I'm creating a Cartogram
object by supplying the dataframe and the headings on which to operate. I can then run the dorling()
method on the Cartogram
object, which returns the cartogram as a new dataframe. I then plot the dorling cartogram over the top of the base map of Europe, using GeoDataFrame's built-in plot()
.
You can follow the same method to generate a non-contiguous cartogram (where the countries are scaled on their centre-point proportional to the value field), by replacing the dorling()
method with non_contiguous()
.
fig, ax = plt.subplots(1)
ax.axis('equal')
ax.axis('off')
gdf = gpd.read_file('https://raw.githubusercontent.com/JosephBARBIERDARNAL/misc-dataviz/main/country-co2/data.geojson')
gdf['geometry'] = gdf['geometry'].to_crs(crs=3857)
gdf.plot(color='w', ax=ax, zorder=0, edgecolor='0', linewidth=0.1, legend=False)
cart = cartogram.Cartogram(gdf, 'co2Capita', 'country', 'geometry')
dorling = cart.dorling(iterations=100, stop=None)
dorling.plot(color='w', ax=ax, zorder=0, edgecolor='0', linewidth=0.1, legend=False)
# Plot Figure
plt.savefig("./out/testing.png", dpi=1200)
If you're looking for the fancier, density-equalizing cartograms like this, unfortunately I haven't implemented those (yet, depending on if I get time outside of work).
from ecmm428-pycart.
The image itself looks like this:
from ecmm428-pycart.
Yes, I'm mainly looking for density-equalising cartograms ^^, as in the example below. Thanks for your example though, but it's less in line with what we'd like to add to the python graph gallery
![Screenshot 2024-06-14 at 11 48 30](https://private-user-images.githubusercontent.com/79746670/339721854-f289750a-f6ba-49d0-b2e4-fbbace92fcfc.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIxNjk5OTMsIm5iZiI6MTcyMjE2OTY5MywicGF0aCI6Ii83OTc0NjY3MC8zMzk3MjE4NTQtZjI4OTc1MGEtZjZiYS00OWQwLWIyZTQtZmJiYWNlOTJmY2ZjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzI4VDEyMjgxM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWNiYzI0OWU3OWZjZmMyNGQ5ZjkwYWY2ODViYWQxY2FkMWNjMzIwYmEzZDY5ZWM2NmZhMmVkMDQyZjg5ODc4OWMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.dCJWjvWhP5MKS6-RfcykyTol0bs-MjtGPlZZNt2YgMQ)
I have no idea how complex it is to implement? This already exists in R but unfortunately we don't have much in Python
from ecmm428-pycart.
Yeah, I had tried to implement this previously but had little success. Unfortunately given the amount of time I have outside of work, I won't be able to implement this any time soon.
from ecmm428-pycart.
Completly understand! wish you the best
from ecmm428-pycart.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ecmm428-pycart.