I am relatively new to programming.
I'm trying to run the following:
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
my_map = Basemap(projection = 'ortho', lat_0=50, lon_0=-100,
resolution = 'l', area_thresh=1000.0)
my_map.drawcoastlines()
my_map.drawcountries()
my_map.fillcontinents(color='red')
plt.show()
However, I get "AttributeError: 'AxesSubplot' object has no attribute 'get_axis_bgcolor'"
I'm using python 3.6, matplotlib 2.2.0, basemap 1.0.7. They were downloaded using Anaconda.
OS - Mac 10.12.4
How do I get rid of this error?
The matplotlib deprecated the get_axis_bgcolor. You'll need to update basemap to version 1.1.0 to fix this error. It's installable via conda-forge, via:
conda install -c conda-forge basemap
In case you'll get error like, "Unable to open boundary dataset file. Only the 'crude' and 'low', resolution datasets are installed by default." Install, the additional files via:
conda install -c conda-forge basemap-data-hires
In addition to #user45237841's answer, you can also change the resolution to c or l to resolve this error Unable to open boundary dataset file. Only the 'crude' and 'low', resolution datasets are installed by default.
my_map = Basemap(projection = 'ortho', lat_0=50, lon_0=-100,
resolution = 'c', area_thresh=1000.0)
# c is for crude and l is for low
if you are using Jupyter-notebook make sure that using --yes to processing package installing on platform. conda install -c conda-forge basemap-data-hires --yes
If you don't want to update just replace get_axis_bgcolor with get_facecolor in \site-packages\mpl_toolkits\basemap\__init__.py file.
Line 1623: fill_color = ax.get_facecolor()
Line 1767: axisbgc = ax.get_facecolor()
Related
I'm executing this code on Kaلgle, and install autokeras library on it,
!pip install autokeras
import matplotlib.pyplot as plt
import pandas as pd
import datetime
%matplotlib inline
#Control the default size of figures in this Jupyter notebook
%pylab inline
pylab.rcParams['figure.figsize'] = (14, 9) # Change the size of plots
#cib = pd.read_csv("../input/balmhils1/balmhils1015.csv")
# load data from csv
cib_f = pd.read_csv("../input/jkse1234/JKSE.csv") # load data from csv
f, ax = plt.subplots(figsize=(11,8))
plt.xlabel("Number of trading day")
plt.ylabel("Close price")
but I got this error.
No module named 'keras_tuner'
Upgrade the keras_tuner
!pip install keras-tuner --upgrade
I had a similar issue using PyCharm. When I installed the keras-tuner package in the Anaconda 3 prompt, I got the message that everything is already installed. The problem was, that the keras-tuner was installed in my base environment and not in the environment (virtual) which I use in PyCharm. You simply need to do the following.
check out your environments in the anaconda prompt using: conda env list
you will probably see the * on the base environment
now change to your working environment for example conda activate tf_cpu -> tf_cpu needs to be changed by your envs name (see on your list)
install your package such as pip install keras_tuner
I installed matplotlib on Anaconda Prompt with conda install -c conda-forge matplotlib.
However, when I run import matplotlib.pyplot as plt on Spyder 4.1.5 (with Python 3.7), I got an error message:
ModuleNotFoundError: No module named 'matplotlib.pyplot'
Before getting this error message, I installed matplotlib_scalebar with conda install -c conda-forge matplotlib-scalebar. I had no issue importing matplotlib.pyplot before this, and I suspect that installing this might have caused the problem.
Under C:\ProgramData\Anaconda3\Lib\site-packages, I have folders with the following names:
matplotlib
matplotlib-3.0.2.dist-info
matplotlib-3.3.2.dist-info
I'm not sure if having different folders (3.0.2 and 3.3.2) is an issue here.
How can I fix this No module issue?
I have recently started using Python 3.5 and Anaconda on my Windows pc. I am trying to plot a map. However, When I am in my Jupyter notebook and i type the command
import mpl_toolkits.basemap
I get an error message saying 'no module name' 'mpl_toolkits.basemap'
However, I have the module downloaded and in the same C:\Users\Geena file as my .matplotlib, .ipython, .jupyter files, etc.
Anyone know how I can fix this?
I've had this issue with anaconda on my windows 7.
I found the way to fix it with python 3.5:
You need to run with administrator rights "Anaconda Prompt" and in "Anaconda Prompt" run following command:
conda install -c conda-forge basemap-data-hires=1.0.8.dev0
, it will show new packages that you need to install and will ask you to install it - say 'Yes'.
After that new packages will be installed and the issue "import mpl_toolkits.basemap" will be fixed.
Thank you.
Currently, basemap is not compatible with python 3 for windows users. So, if you try conda install basemap and you have python 3 installed in windows, you'll see a message pointing out that a conflict was found with python 3.
I solved this by installing a python 2.7 environment. Try this:
http://conda.pydata.org/docs/py2or3.html
Then you just activate the python 2 environment. For example: activate py27 (py27 is the identifier of my python 2.7 environment).
After that, you can run conda install basemap with no conflict.
I'm using python 3.6.4 on Windows 7 Family Premium (32bit).
Because I was a bit frustrated by the message "no module named 'mpl_toolkits.basemap'", I searched for and tried a dozen of solutions without success : various versions, building from source, problems with VS version, nmake, ... You all know what I mean ;-)
I finally found a quite simple solution that works perfectly well for me :-) Here it is !
from here I downloaded basemap‑1.1.0‑cp36‑cp36m‑win32.whl
I changed the current dir to my download dir
I installed the wheel with python -m pip basemap‑1.1.0‑cp36‑cp36m‑win32.whl
I did the same for matplotlib‑2.2.3‑cp36‑cp36m‑win32.whl
You DO read the versions correctly : matplotlib 2.2.3 and basemap 1.1.0
Everything works fine for me and I finally can plot OSM POI's on a map of Belgium, without any 'trickery' at import :
import requests # to fetch OSM data
import json # to get the response
from mpl_toolkits.basemap import Basemap # ... Belgium is there !
import numpy as np # for arrays
import matplotlib.pyplot as plt # to build the populated map
Big big thanks to Christoph Gohlke (Danke Dir Christoph !) who did all the wonderful job !
When you have Anaconda, you don't download modules anywhere. In your command prompt, you type
conda install basemap
and it is installed with all its dependencies.
Anaconda requires an unusual install command for basemap 1.0.7.
https://anaconda.org/anaconda/basemap
To install this package with conda run:
conda install -c https://conda.anaconda.org/anaconda basemap
I just had this issue as well. All you need to do is update matplotlib by doing the following:
pip install --upgrade matplotlib
mpl_toolkits is part of matplotlib and just needs to be updated.
If you're using anaconda, the easiest thing to do is described here: in the conda prompt (as admin), type conda install -c anaconda basemap.
For people of the future : "Basemap is deprecated in favor of the Cartopy project."
https://matplotlib.org/basemap/users/intro.html#cartopy-new-management-and-eol-announcement
I have installed Anaconda (version 1.6.2) installed on my 64 bit machine. It comes with a great set of libraries, but I also need Basemap, part of matlibplot, but it is not included with the Anaconda install. I attempted to install Basemap and move the files in the Anacaonda\Lib\site-packages\mpl_toolkits directory since it is part of the mpl_toolkits library. However when I attempt to run a script, I keep getting the errors:
"No module named _geoslib"
"Cannot import pyproj"
I found the pyproj library. Do I need it? Where can I find geoslib? And how do I get Basemap to work?
What you nees is to change your path first, by:
$ export PATH=~/anaconda/bin:$PATH
and then,
$ conda install basemap
( I assumed you are in Linux)
source:http://docs.continuum.io/anaconda/faq.html
If your on Windows try installing Basemap from the Sourceforge executable, these should include GEOS and PROJ4 dependencies of Basemap.
I believe all that is needed is to update matplotlib, I just had this problem and doing this worked for me:
pip install --upgrade matplotlib
I'm trying to install matplotlib under Windows Vista. Both python itself and numpy are working for me.
I installed matplotlib via the executable basemap-1.0.2.win32-py2.7 and followed the official instructions. But running from matplotlib import * gives me the following error:
No module named matplotlib
Any ideas how to get matplotlib working?
you can install by pip install matplotlib
Make sure that you already installed setuptools, numpy, python-dateutil, pytz, pyparsing, and cycler before that.
basemap is not the installer for matplotlib.
basemap is a library of the matplotlib toolkit for plotting 2D data on maps, you need to indepently install matplotlib to use it.
You can get matplotlib from here
from pylab import *
This works on a proper the default scipy/pylab/matplotlib setup. And to get you started:
> hist(randn(10000))
> show()
Matplotlib is a part of the pylab suite
If you are installing matplotlib under windows using anaconda. Here are the steps..
I am using Anaconda 1.8.7
Goto your Anaconda Navigator and choose Environments
Click on the arrow and choose Open terminal
Type conda install matplotlib
That should do the trick. For specific versions and to install onto specific environments within annaconda you can utilise the = and -n / name option
https://conda.io/docs/commands/conda-install.html
Matplotlib Installation using command prompt / Annaconda Terminal
Open Command Prompt
C:\Users\Uname>python -m pip install matplotlib
Matplotlib requires some of the following dependencies:
FreeType libpng NumPy setuptools cycler dateutil kiwisolver pyparsing