在Jupyter Notebook中将数据点绘制到matplotlib底图上 [英] Plotting data points onto matplotlib Basemap in Jupyter Notebook

查看:97
本文介绍了在Jupyter Notebook中将数据点绘制到matplotlib底图上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

B.让pyplot不要关闭数字

另一种选择是让pyplot不关闭数字.这是该答案的第二个选择:

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?

解决方案

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

这篇关于在Jupyter Notebook中将数据点绘制到matplotlib底图上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆