代码未找到matplotlib.pyplot模块

时间:2019-06-12 21:41:38

标签: python python-3.x matplotlib matplotlib-basemap

我正在尝试运行一个程序以重新投影卫星图像。我在命令上运行代码,代码如下:

import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import numpy as np # Import the Numpy package
from remap import remap # Import the Remap function
from cpt_convert import loadCPT # Import the CPT convert function
from matplotlib.colors import LinearSegmentedColormap 
from netCDF4 import Dataset

# Load the Data
# Path to the GOES-16 image file

#path = '/Volumes/Anthonys_backup/Masters_Thesis/Satellite_Data/new2/C13/OR_ABI-L2-CMIPF-M3C13_G16_s20180400500385_e20180400511163_c20180400511242.nc'
path = '/home/alighezzolo/Casos/ANTHONY/OR_ABI-L2-CMIPF-M3C13_G16_s20180010000387_e20180010011165_c20180010011246.nc'

nc = Dataset(path)
H = nc.variables['goes_imager_projection'].perspective_point_height

# Choose the visualization extent (min lon, min lat, max lon, max lat)
extent = [-90.0, -40.0, -20.0, 10.0]

# Choose the image resolution (the higher the number the faster the processing is)
resolution = 1.0

# Call the reprojection funcion
grid = remap(path, extent, resolution, 'HDF5')

# Read the data returned by the function
data = grid.ReadAsArray()

# Plot the Data 
# Create the basemap reference for the Rectangular Projection
bmap = Basemap(resolution='h', llcrnrlon=extent[0], llcrnrlat=extent[1], urcrnrlon=extent[2], urcrnrlat=extent[3], epsg=4326)

# Draw the countries and Argentinian states shapefiles
bmap.readshapefile('/home/alighezzolo/BTCH13/SHAPES/008_limites_provinciales_LL','008_limites_provinciales_LL',linewidth=.5,color='black')
#bmap.readshapefile('/Users/anthonycrespo/Desktop/Satelite/arg_adm1/ARG_adm1','ARG_adm1',linewidth=.5,color='black')
#bmap.readshapefile('/Users/anthonycrespo/Desktop/Satelite/Countries_Shape/ne_10m_admin_0_countries','ne_10m_admin_0_countries',linewidth=.7,color='black')

# Draw parallels and meridians
bmap.drawcoastlines(linewidth=1., linestyle='solid', color='black')
bmap.drawparallels(np.arange(-90.0, 90.0, 10.0), linewidth=0.25, color='white', labels=[True,False,False,True])
bmap.drawmeridians(np.arange(-180.0, 180.0, 10.0), linewidth=0.25, color='white', labels=[True,False,False,True])

# Converts a CPT file to be used in Python
#cpt = loadCPT('/Users/anthonycrespo/Desktop/Satelite/IR4AVHRR6.cpt')
cpt = loadCPT('/home/alighezzolo/BTCH13/CPT/IR4AVHRR6.cpt')
# Makes a linear interpolation
cpt_convert = LinearSegmentedColormap('cpt', cpt)

# Plot the GOES-16 channel with the converted CPT colors
bmap.imshow(data, origin='upper', cmap=cpt_convert, vmin=170, vmax=378)

# Date and time
import datetime

time_var = nc.time_coverage_start
iyear = time_var[0:4]
imonth = time_var[5:7]

import calendar

cmonth = calendar.month_abbr[int(imonth)]
iday = time_var[8:10]
itime = time_var[11:19]
itimehr = time_var[11:13]
itimemn = time_var[14:16]

ctime_string = iyear +' '+cmonth+' '+iday+'  '+itime+' GMT'
ctime_file_string = iyear + imonth + iday + itimehr + itimemn

filestring = "C13_" + iyear + imonth + iday + "_" + itimehr + itimemn + ".jpg"
filestring = "C13_" + iyear + imonth + iday + "_" + itimehr + itimemn + ".png"
time_string = 'GOES-16 ABI Band 13\n"Clean" LW IR Window\n%s '%ctime_string


# Add a title to the plot
plt.title('GOES-16 Band 13\n"Clean" LW IR Window\n%s '%ctime_string)

# Insert the legend at the bottom
bmap.colorbar(location='right', label='Brightness Temperature [K]')

# Show the plot
#plt.show()
DPI = 150
plt.savefig(filestring, dpi=DPI, bbox_inches='tight', pad_inches=0)

但是返回以下错误:

(base) Anthonys-MacBook-Pro:New_code_for_plotting anthonycrespo$ python Reprojection.py
Traceback (most recent call last):
  File "Reprojection.py", line 4, in <module>
    import matplotlib.pyplot as plt # Import the Matplotlib package
ModuleNotFoundError: No module named 'matplotlib.pyplot'

我已经仔细检查了“ conda list”,它具有最新的matplotlib版本,我尝试了“ pip install matplotlib”,系统告诉我我具有最新版本。

运行代码的环境为:

Mac OS Mojave 10.14.5
Python 3.7.3 (default, Mar 27 2019, 16:54:48) 
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

可能您有多个python版本,或者您以某种方式正在使用虚拟环境(提示符开头的“(基本)”是什么?)。尝试检查您使用的python版本:

> which python
> which python3

和下一次查找(如果您启用了任何虚拟环境)。