%matplotlib inline does not show any plot on jupyter notebook - matplotlib

matplotlib.pyplot takes a long time to run and finally no plot shows on the screen
But matplotlib.back_end() gives the following
u'TkAgg'
Can someone suggest a solution?
NOTE: I installed matplotlib using pip install matplotlib

I had a similar problem working with jupyter notebook on a Mac OSX 10.10.5
In the end I fixed it by reinstalling IPython and dependencies with the command
pip install -U --force-reinstall numpy matplotlib pyzmq jinja2 ipython

Related

How to plot an image using PIL or Matplotlib

I am trying to plot an image in python using either PIL or Matplotlib. I have tried both
import matplotlib.pyplot as plt
and
from PIL import Image
But I get the same error:
ImportError: cannot import name '_imaging' from 'PIL'
I have updated pillow and matplotlib packages but no success
You can read the image using open cv and then plot it using matplotlib.
img_name = cv2.imread("image.jpeg")
plt.imshow(img_name)
plt.show()
This usually happens when folk use python and pip from different packages, distributions or versions. I mean you install a package with pip into one package/distribution/version and then try and use it from a different package/distribution/version of Python.
So, if you normally start Python using:
python
then run:
type python
Whereas if you normally start Python using:
python3
then run:
type python3
On my machine I get:
type python3
python3 is /Library/Frameworks/Python.framework/Versions/3.9/bin/python3
so now I know which Python I am using.
Now you need to see which pip you are using. So, if you normally start pip with:
pip
then run:
type pip
Whereas if you normally start pip with:
pip3
then run:
type pip3
On my machine I get:
type pip3
pip3 is /Library/Frameworks/Python.framework/Versions/3.9/bin/pip3
So now you can see that my pip3 is installing packages for python3 exactly where it can find them.

ImportError: IProgress not found. Please update jupyter and ipywidgets although it is installed

I am using jupyter notebook and installed.
ipywidgets==7.4.2 widgetsnbextension pandas-profiling=='.0.0
and also I ran:
!jupyter nbextension enable --py widgetsnbextension
but when running:
from pandas_profiling import ProfileReport
profile = ProfileReport(df, title="Pandas Profiling Report", explorative=True)
profile.to_widgets()
I get the error:
ImportError: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
Any idea why?
Tried proposed solutions.
I tried everything you mentioned in a new environment using conda and I had another issue related to the version of ipywidgets (a bug found in Github with comments saying that got solved after using last version). I solved the problem I had installing last version of ipywidgets. Here is my process:
Create a new environment using conda (I use miniconda):
conda create --name teststackoverflow python=3.7
Activate new environment:
conda activate teststackoverflow
Install jupyter:
pip install jupyter
Install all the libraries without specific versions to get the last ones:
pip install ipywidgets widgetsnbextension pandas-profiling
Run jupyter notebook in the console to turn on the notebooks server and create a new notebook.
Run this line in a new cell:
!jupyter nbextension enable --py widgetsnbextension
With the result:
Enabling notebook extension jupyter-js-widgets/extension...
- Validating: OK
Run some sample code to define df:
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [1, 2, 3, 4]})
Run the code you provided:
from pandas_profiling import ProfileReport
profile = ProfileReport(df, title="Pandas Profiling Report", explorative=True)
profile.to_widgets()
Final output looks good:
this had worked for me (for all of you who prefer pip instead of conda..)
in your virtualenv run
pip install ipywidgets
jupyter nbextension enable --py widgetsnbextension
or, if you prefer to run it in your notebook
!pip install ipywidgets
!jupyter nbextension enable --py widgetsnbextension
and in your notebook add
from ipywidgets import FloatProgress
Installing ipywidgets and building Jupyter Lab did the trick for me.
Make sure you activate the correct conda environment
Install ipywidgets: conda install -c conda-forge ipywidgets
To build Jupyter Lab, you need to have nodejs > 12.0.0 installed. Check the latest version number from Anaconda website and install nodejs specifying the package number e.g. conda install -c conda-forge nodejs=16.6.1
Stop Jupyter Lab
Build Juyter Lab: jupyter lab build
Start Jupyter Lab
I ran into the same error within the jupyter lab and I just installed ipywidgets using conda install -c conda-forge ipywidgets command.
I ran into the same error. On M1 mac, I change from tqdm.notebook import tqdm as tqdm to from tqdm import tqdm. Hope it helps. Original post: https://github.com/CosmiQ/solaris/issues/392#issuecomment-759238485

pandas_profiling.ProfileReport(dataframe) in google colab

Why doesn't pandas_profiling.ProfileReport(dataframe) work in google colab?
Returns a type error.
TypeError: concat() got an unexpected keyword argument 'join_axes'
Just use pandas-profiling version 2.7.1 and you are good to go.Run this command in the colab !pip install pandas-profiling==2.7.1
Aishah Ismail's post on Medium may help you fix this issue.
Install the pandas-profiling package using pip.
! pip install https://github.com/pandas-profiling/pandas-profiling/archive/master.zip
Restart your kernel = Go to "Runtime" in the option menu and click "Reset All Runtimes"
Execute your code to create your dataframe and create the pandas profile.
import pandas as pd
import numpy as np
from pandas_profiling import ProfileReport
df = pd.read_excel('fileName.xlsx')
profile = ProfileReport(df)
profile.to_notebook_iframe()
You may need to pip install pandas-profiling if the import above does not work.
!pip install pandas-profiling==2.7.1 Re-execute your code after the pip install.
When you try to display the profile do not use .to_widgets()--it isn't working in Colab.
If the above doesn't work, I suggest switching to Jupyter Lab or Jupyter Notebook. The pandas profile dashboard works well in the Jupyter environment.
I hope this helps! Pandas-Profiling a wonderful EDA tool--such a time saver.

ModuleNotFoundError for pandas_datareader: Jupyter Notebook using different packages from conda environment

I am using Anaconda windows v5.3.
I am getting the error:
ModuleNotFoundError: No module named 'pandas_datareader'
When I tried to print out the packages used by Jupyter Notebook, I realized that pandas_datareader is not in, and a different version of pandas (0.23.0) is used:
import pkg_resources
for i in pkg_resources.working_set:
print(i)
Output
...
pandocfilters 1.4.2
pandas 0.23.0
packaging 17.1
openpyxl 2.5.3
...
This differs from the library installed in the pyfinance environment:
>conda list
# Name Version Build
pandas 0.20.3 py36_0
pandas-datareader 0.4.0 py36_0
Hence, pandas_datareader seem to work in the python shell in the command prompt, but not in jupyter notebook. Are there anyways to sync jupyter notebook environment to the conda environment?
I realized to sync jupyter notebook you just have to do:
conda install jupyter

Matplotlib crashes Python on Windows 10

I installed Anaconda on my Windows10 machine and Matplotlib will cause Python to crash once I import it by calling import matplotlib.pyplot:
When I execute conda list on my shell, this is the value of the matplotlib entry:
matplotlib 2.2.2 py36_1 conda-forge
I guess I am not the only one with this critical problem. Any idea how to solve this?
Found a fix - sharing here. Running the following command solved the problem:
conda update qt pyqt