问题
Link to full code
I am able to successfully create a Basemap of the US within a Jupyter Notebook complete with shapefile, coloring, and borders in Cell 4.
I am trying to plot many data points onto this Basemap with the following line in Cell 8:
m.plot(x, y, marker='o', markersize=data, color='#444444', alpha=0.8, latlon=True)
The data gets plotted, but I lose all of my Basemap's formatting and shaping. Effectively, I want Cell 8 overlayed on Cell 4. I suspect I am not plotting these shapes on the same plane.
Additionally, plt.show() gives me nothing. What am I missing?
回答1:
A. using a figure instance
The idea can be to explicitely specify the axes to plot to at Basemap creation.
Cell 1:
fig, ax = plt.subplots()
m = Basemap(... , ax=ax)
Cell 2: # do other stuff
Cell 3:
# plot to map:
m.plot(...)
Cell 4:
# state figure object to show figure (when inline backend is in use)
fig
Screenshot of example:
B. let pyplot not close figures
The other option would be to let pyplot not close the figures. This is the second option from this answer: How to overlay plots from different cells?
%config InlineBackend.close_figures=False
来源:https://stackoverflow.com/questions/46381620/plotting-data-points-onto-matplotlib-basemap-in-jupyter-notebook