I want to use matplotlib basemap, using Anaconda in a Jupyter Notebook. while running this:
from mpl_toolkits.basemap import Basemap
I get the following error:
KeyError: 'PROJ_LIB'
What I've tried and haven't worked:
conda install basemap
and
conda install basemap -c conda-forge
I checked similar questions here but couldn't find a proper answer.
If you already haven't found the solution, adding
import os
os.environ['PROJ_LIB'] = '<path to anaconda>/anaconda3/share/proj'
to your code preamble will do the job.
Related
I tried to install pyplot using 'pip install pyplot' in command prompt while it was installing by mistake i closed command prompt then again i am trying to install pyplot using the same command but it was not installing.Can anyone guide me how to install pyplotKindly find the error in this image
error rectification in installing pyplot
pyplot is part of a matplotlib.
In order to install pyplot you should install matplotlib
pip install matplotlib
So you can "import matplotlib.pyplot"
You can go to https://pypi.org/project/matplotlib to see and install the version you want.
Then you can import the pylot
from matplotlib import pyplot
Hi everyone, I'm trying to create a network visualization with python using the networkx package. Unfortunately I'm getting a "AttributeError: module 'scipy.sparse' has no attribute 'coo_array'" at the end of my code. I've tried to fix it but every help in the internet points towards upgrading pip or conda which I've done and still get the same error. I'm using jupyter notebooks - any help would be greatly appreciated!
#Prerequisites
import sys
!{sys.executable} -m pip install --user networkx
!{sys.executable} -m pip install --user numpy
!{sys.executable} -m pip install --user pandas
pip install notebook --upgrade
conda upgrade notebook
import networkx as nx
import numpy as np
import pandas as pd
from pathlib import Path
from pandas import DataFrame
#Read in Source File - NB this must match the schema requirements
df_InputData = pd.read_excel("/Users/paulkruse/Desktop/FR/Fr1.xlsx")
Src_Column = 'Source ID'
Tgt_Column = 'Target ID'
print(df_InputData);
#Nodes are positioned using the Fruchterman-Reingold force-directed algorithm.
Q = nx.Graph()
arr_SrcTgt= np.array(df_InputData[[Src_Column, Tgt_Column]])
print(arr_SrcTgt);
Q.add_edges_from(arr_SrcTgt)
dict_Coords = nx.spring_layout(Q)
It seems that your scipy version is out of date. The most recent version 1.8.1 certainly has coo_array function. One way to resolve this should be to upgrade scipy. If you're doing this from inside jupyter notebook, then use
!pip install --user scipy==1.8.1
Make sure to restart kernel after installation.
I'am trying to run a simple geopandas code using ANACONDA spyder. However, I'am encountering an error.
I have included the code and the error as below:
--
here is the code:
import geopandas as gpd
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
world.plot()
import matplotlib.pyplot as plt
plt.show()
--
here is the error:
File "C:\Users\usr\Anaconda3\lib\site-packages\geopandas\plotting.py", line 90, in plot_polygon_collection
"The descartes package is required for plotting polygons in geopandas."
ImportError: The descartes package is required for plotting polygons in geopandas.
--
I checked online and I couldn't find troubleshooting solution for this problem. Can anyone please help and advise?
appreciated.
Depending on your package manager install descartes. In anaconda prompt do the following:
conda install descartes
Replace conda with pip or an other package manager of your use.
The above didn't work for me. I ran the below command instead and it worked:
pip install descarteslabs[complete]
Add --user on the end if you encounter any permissions errors
Hi I am following a tutorial that was using matplotlib.finance to use candlestick.ohlc. When researching I found out that that lib was deprecated and to use mlp_finance. I believe I have installed it by running the command prompt and entering the line pip install mpl_finance. The result that I get this
I tried re running the script but I still get the error:
from mpl_finance import candlestick_ohlc
ModuleNotFoundError: No module named 'mpl_finance'
I checked the python library path and I don't see a folder labeled mlp_finance(Im not sure if Im suppose to). But I do see a file labeled mpl_finance-0.10.0-py3.7.egg
Any help on resolving this issue? Downloaded the git package and ran the command prompt install
ran the command line pip install git clone https://github.com/matplotlib/mpl_finance.git mpl_finance.git
I've got the same error you told, but I resolved it as below.
First, install mpl_finance
pip install https://github.com/matplotlib/mpl_finance/archive/master.zip
Second, upgrade mpl_finance
pip install --upgrade mplfinance
Hope that this will work.
If you want to follow that tutorial on mpl_finance, you can do so by installing the new mplfinance:
pip install --upgrade mplfinance
Then every place the tutorial tells you to import from mpl_finance change the import to from mplfinance.original_flavor, for example:
change:
from mpl_finance import candlestick_ohlc
to
from mplfinance.original_flavor import candlestick_ohlc
if you using Anaconda - To install this package with conda run:
conda install -c conda-forge mplfinance
You need to install matplotlib/mpl_finance at https://github.com/matplotlib/mpl_finance
git clone https://github.com/matplotlib/mpl_finance.git mpl_finance.git
cd mpl_finance.git
python setup.py install
mpl_finance has been deprecated, just install the module as mplfinance.
pip install mlp_finance will solve the issue
I'm working in Ubuntu as Virtual-Box guest on top of Windows machine (as host), and I am attempting to run my python script from the terminal. I had difficulty installing matplotlib using pip install. I managed to install it using
sudo apt-get install python-matplotlib
However, I am unable to bring up an image I have created in my code:
import numpy as np
import matplotlib.pyplot as plt
import random as random
from random import randrange
image = plt.imshow(mymatrix)
plt.show()
If I import matplotlib as:
import matplotlib as plt
I am recieving the following error on attempting to run the script:
AttributeError: 'module' object has no attribute 'imshow'
If I import matplotlib as:
import matplotlib.pyplot as plt
I recieve the following error:
raise ImportError, str(msg) + ', please install the python-tk package'
ImportError: No module named _tkinter, please install the python-tk
package
On attempting to install python-tk using 'pip install python-tk' this is what I'm getting:
~/ising $ pip install python-tk Collecting python-tk Could not find
a version that satisfies the requirement python-tk (from versions: )
No matching distribution found for python-tk
I'm unsure if I have in fact incorrectly installed matplotlib from the beginning. I am aware pyplot is not automatically imported with matplotlib, could the same be true for installing it from the console? Seems like I have tried everything at this stage.
The problem appears to be that you do not have a graphical backend installed. The error you are getting about Python Tk is happening because normally Tk comes with any Python distribution, so you should have at least that. You can install any Python bindings for Tk, Pyqt4, Pyqt5, Wx, GTK, (possibly others) to get a working interactive graphical backend. Check the package repository for the actual package names to install.
Keep in mind that functions like imshow are part of the (sub)package matplotlib.pyplot, not matplotlib itself. import matplotlib as plt is simply wrong if you intend to do plt.imshow(...). The correct import is either from matplotlib import pyplot as plt or import matplotlib.pyplot as plt.
According to the documentation here try this
python -mpip install -U pip
python -mpip install -U matplotlib