Replies: 2 comments 2 replies
-
I don't know of anyone having tackled such a project for Textual, but if anyone were to do so this project might be a good source of inspiration. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Here's something I quickly hacked together using GeoPandas and rich-pixels import warnings
import geopandas as gpd # type: ignore
import matplotlib.pyplot as plt
from PIL import Image
from rich_pixels import Pixels
from textual.app import App, ComposeResult
from textual.widgets import Static
MAP_FILENAME = "world_population.png"
# Ignore that the geopandas.dataset module is deprecated!
warnings.filterwarnings("ignore", category=FutureWarning)
def generate_map_image() -> None:
world = gpd.read_file(
gpd.datasets.get_path("naturalearth_lowres"), # type: ignore
)
# Remove Antarctica
world = world[world["continent"] != "Antarctica"]
# Remove axis labels
ax = world.plot(column="pop_est")
ax.set_axis_off()
# Save as image
plt.savefig(MAP_FILENAME, bbox_inches="tight", transparent="True")
class WorldPopulationApp(App):
CSS = """
Screen {
align: center middle;
}
"""
def compose(self) -> ComposeResult:
with Image.open(MAP_FILENAME) as image:
size_ratio = image.width / self.size.width
new_width = int(image.width / size_ratio)
new_height = int(image.height / size_ratio)
resized_image = image.resize(
(new_width, new_height),
Image.Resampling.NEAREST,
)
pixels = Pixels.from_image(resized_image)
yield Static(pixels)
if __name__ == "__main__":
generate_map_image()
app = WorldPopulationApp()
app.run() |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Ever since I spotted the micro site that @stripe put forward to demonstrate their capabilities for Black Friday and Cyber Monday (which I know was a web based interface). I have been intrigued about if there are any geo visualisation libraries in
python
that allow plotting some basic data on a map?Something as simple as a heat map based on geography of users.
Keen to hear if anyone knows of any such projects out there. The obvious Google terms leads to projects that quite a GUI.
Beta Was this translation helpful? Give feedback.
All reactions