Reputation: 78
I am trying to create a visualisation in Altair that overlays major rivers onto a map of Europe, and some of the surrounding countries. I used this website to download a custom GeoJSON file of Europe, Asia and Africa. I then managed to successfully plot the base map using GeoPandas (imported as gpd) in the following code:
custom_world = gpd.read_file('customgeo.json')
base = alt.Chart(custom_world).mark_geoshape(color='lightgrey').encode(
tooltip=[alt.Tooltip('name:N', title='Country')]
).properties(
width=600,
height=400
).project(
scale=400, translate=[100, 550]
)
base
This is the output visualisation of JUST the map data
I am using major river GeoJSON data from this website; specifically this dataset. Now, when I attempt to plot this, Altair returns a somewhat correct output, as some of the rivers are plotted as expected, but the map is littered with obscure polygons.
majorrivers = gpd.read_file('major-rivers.geojson')
rivers = alt.Chart(majorrivers).mark_geoshape(
filled=False,
strokeWidth=2
).properties(
width=600,
height=400,
title = 'Waterways'
).project(
scale=400, translate=[100, 550]
)
base + rivers
As you can see from the output, something isn't quite right
It might be worth noting that the problem still persists even when I don't layer the chart and just plot 'rivers'. After numerous Google searches, I still find myself at a loss, so any help would be very much appreciated!
Upvotes: 1
Views: 434
Reputation: 78
I'm answering my own question as I seemed to have fixed it, and want to share in case someone comes across this issue too.
It might have been important to note that I am using a Jupyter Notebook to create this visualisation. I just so happened to open another Notebook with a known working Altair visualisation and found the same obscure polygons present. To fix it, I closed JupyterLab, opened it back up and ran all cells in the Notebook.
Using the same code, this seemed to produce the desired output.
Upvotes: 1