Closed aegonwolf closed 2 years ago
additional info, the figsize is actually correct at first, I get this matplotlib output from creating it if I use the ax=ax argument:
fig, ax = plt.subplots(1,figsize=(height/96, width/96), dpi = 96)
<Figure size 9803x10000 with 1 Axes>
The figsize
is whatever you set it to. However, saving the image to disk does change the size of what gets saved. As you noticed, even matplotlib does this itself directly. OSMnx does it as well, because it constrains the saved image to the actual visualized area. Otherwise, you end up with axes, margins, and padding (which all make up part of the matplotlib figure). If you want a specific figure size saved with all that extra stuff around its perimeter, you create an ax
, pass it into the plot_graph
function, then save it to disk yourself the usual matplotlib way. At that point you are only constrained by what the matplotlib package does.
You can see how OSMnx configures the ax
here and how it configures the saved image here.
Read these instructions carefully
Problem description
Environment information
conda list
orpip list
then paste the output between the two "details" tags below)Provide a complete minimal reproducible example
bgcolor = "#061529" north = -1.2656497829259836 south = -1.3099201363982285 east = 36.76232691456512 west = 36.71737787067992 graph = ox.graph.graph_from_bbox(north, south, east, west) height, width = desired_height, desired_width # (9803, 10000) in my case fig, ax = ox.plot_graph(graph, node_size=0, bbox = (north, south, east, west), figsize=(height/my_dpi, width/my_dpi), dpi = my_dpi, bgcolor = bgcolor, save = True, filepath='image.jpg', edge_color=roadColors, edge_linewidth=roadWidths, edge_alpha=1)
fig.tight_layout(pad=0) fig.savefig("nairobi_big3.jpg", figsize=(height/my_dpi, width/my_dpi), dpi = my_dpi, bbox_inches='tight', format="jpg", facecolor=fig.get_facecolor(), transparent=False)
Your example code snippet here must be minimal so it doesn't contain extraneous code unrelated to your specific problem and it must be complete so we can independently run it from top to bottom by copying/pasting it into a Python interpreter. That means all imports and all variables must be defined. If you're unsure how to create a good reproducible example, read this guide. Do not post a screenshot of your code or error message: provide it as text.
it's the same for jpg and png haven't tried others