简体   繁体   English

如何在MatPlotLib底图中添加标题?

[英]How do I add a title to my MatPlotLib basemap?

I tried 我试过了

matplotlib.pyplot.title("Analysis of Tsunamis in Southeast Asia")

but the Python interpreter notes that NameError: name 'matplotlib' is not defined even though I am sure that I imported pyplot earlier: 但是Python解释器指出,即使我确定早先导入pyplot, NameError: name 'matplotlib' is not defined name'matplotlib':

import matplotlib.pyplot

How can I add a title to my map? 如何为地图添加标题?

My guess is that you imported pyplot like this 我的猜测是你像这样导入了pyplot

import matplotlib.pyplot as plt
# or from matplotlib import pyplot

In which case you'd need to do 在这种情况下,您需要做

plt.title("Analysis of Tsunamis in Southeast Asia")
# or pyplot.title("Analysis of Tsunamis in Southeast Asia")

I believe that you might have over thought yourself. 我相信您可能已经考虑过了。 By importing the routine matplotlib.pyplot, you have brought the subroutines of pyplot into your current work space. 通过导入例程matplotlib.pyplot,您已将pyplot子例程带入当前工作空间。 Therefore, using the entire name of the function is like saying 因此,使用函数的全名就像说

matplotlib.pyplot.matplotlib.pyplot.title 

-- which is why it's not defined. -这就是为什么它没有定义的原因。 Have you tried just calling: 您是否尝试过仅致电:

title("Analysis of Tsunamis in Southeast Asia")

After looking at some of my subroutines, I think that might be the solution. 看完我的一些子例程后,我认为这可能是解决方案。

try using 尝试使用

from matplotlib.pyplot import * title("Analysis of Tsunamis in Southeast Asia") 来自matplotlib.pyplot import *标题(“东南亚海啸分析”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM