'How do I correctly download a map from osmnx as .svg?
I am new to Python. Just working with OSMnx and wanted to open a map as an svg in Illustrator. This was posted in the GitHub documentation:
# you can also plot/save figures as SVGs to work with in Illustrator later fig, ax = ox.plot_graph(G_projected, save=True, file_format='svg')
I tried it in JupyterLab and it downloaded to my files but when I open it, it is just text. How can I correctly download it and open as SVG? - Thanks!
Solution 1:[1]
Instead of
filename='image', file_format='svg'
Use:
filepath='image.svg'
Solution 2:[2]
Streamlit map is just a wrapper around st.pydeck_chart. This helps making a map chart easily but also has some limitations like setting height and width.
The best option if you want to control the height and width of the presented map is to use the st.pydeck_chart which has a height and width argument.
Here is a code to create a map using st.pydeck_chart:
import streamlit as st
import pandas as pd
import numpy as np
import pydeck as pdk
height = 500
width = 500
df = pd.DataFrame(
np.random.randn(1000, 2) / [50, 50] + [37.76, -122.4],
columns=['lat', 'lon'])
st.pydeck_chart(pdk.Deck(
map_style='mapbox://styles/mapbox/light-v9',
initial_view_state=pdk.ViewState(
latitude=37.76,
longitude=-122.4,
zoom=11,
height=height,
width=width
),
layers=[
pdk.Layer(
'ScatterplotLayer',
data=df,
get_position='[lon, lat]',
get_color='[200, 30, 0, 160]',
get_radius=100,
auto_highlight=True
),
],
))
Output with height=500 and width=500:
Output with height=100 and width=100:
Note - st.map creates a scatter plot chart on top of a map but using st.pydeck_chart gives us more flexibility and options in map creation and design.
Solution 3:[3]
Just call this function _max_width_(80) in your app.py and you’ll be able to always start with wide-mode. More on Custom Render Widths
def _max_width_(prcnt_width:int = 75):
max_width_str = f"max-width: {prcnt_width}%;"
st.markdown(f"""
<style>
.reportview-container .main .block-container{{{max_width_str}}}
</style>
""",
unsafe_allow_html=True,
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | JoScratcherJo |
| Solution 2 | RoseGod |
| Solution 3 | Pluviophile |


