Код не находит модуль matplotlib.pyplot - PullRequest
0 голосов
/ 13 июня 2019

Я пытаюсь запустить программу для перепроектирования спутниковых изображений.Я запускаю код в моей команде, и код выглядит следующим образом:

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", и он имеетпоследняя версия 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 Ответ

1 голос
/ 13 июня 2019

Возможно, у вас есть несколько версий Python или вы как-то используете виртуальную среду (что означает «(базовый)» в начале приглашения?). Попробуйте проверить версию Python, которую вы используете:

> which python
> which python3

и следующий поиск, если у вас включена виртуальная среда.

...