ModuleNotFoundError: No module named matplotlib.pyplot

2024/9/30 11:30:57

When making a plot, I used both Jupyter Notebook and Pycharm with the same set of code and packages. The code is:

import pandas as pd
import numpy as np 
import matplotlib.pyplot as plt   # as in Pycharm
import matplotlib as plt          # as in Jupyterdf = pd.read_csv("/home/kunal/Downloads/Loan_Prediction/train.csv")
df['ApplicantIncome'].hist(bins=50)
plt.show() #this only in Pycharm not in Jupyter.

In Pycharm, the code works well. But in Jupyter Notebook, it has error:enter image description here

I wish someone can help me solve this problem

Answer

I had the same problem and found a solution! Matplotlib was installed on another python installation I have.

Put the following snippet in a cell and execute it, and you should be good to go:

import sys
!{sys.executable} -m pip install matplotlib
https://en.xdnf.cn/q/71088.html

Related Q&A

python linux - display image with filename as viewer window title

when I display an image with PIL Image it opens an imagemagick window but the title is some gibberish name like tmpWbfj48Bfjf. How do I make the image filename to be the title of the viewer window?

Request body serialization differences when lambda function invoked via API Gateway v Lambda Console

I have a simple API set up in AWS API Gateway. It is set to invoke a Python 2.7 lambda function via API Gateway Proxy integration.I hit a strange error in that the lambda worked (processed the body co…

Determining a homogeneous affine transformation matrix from six points in 3D using Python

I am given the locations of three points:p1 = [1.0, 1.0, 1.0] p2 = [1.0, 2.0, 1.0] p3 = [1.0, 1.0, 2.0]and their transformed counterparts:p1_prime = [2.414213562373094, 5.732050807568877, 0.7320508075…

Split datetime64 column into a date and time column in pandas dataframe

If I have a dataframe with the first column being a datetime64 column. How do I split this column into 2 new columns, a date column and a time column. Here is my data and code so far:DateTime,Actual,Co…

Django - Setting date as date input value

Im trying to set a date as the value of a date input in a form. But, as your may have guessed, its not working.Heres what I have in my template:<div class="form-group"><label for=&qu…

ReduceLROnPlateau gives error with ADAM optimizer

Is it because adam optimizer changes the learning rate by itself. I get an error saying Attempting to use uninitialized value Adam_1/lr I guess there is no point in using ReduceLRonPlateau as Adam wil…

How to make add replies to comments in Django?

Im making my own blog with Django and I already made a Comments system.. I want to add the replies for each comment (like a normal comments box) and I dont know what to do this is my current models.py …

Which Regular Expression flavour is used in Python?

I want to know which RegEx-flavour is used for Python? Is it PCRE, Perl compatible or is it ICU or something else?

Python regex: Including whitespace inside character range

I have a regular expression that matches alphabets, numbers, _ and - (with a minimum and maximum length).^[a-zA-Z0-9_-]{3,100}$I want to include whitespace in that set of characters.According to the Py…

Python - how can I override the functionality of a class before its imported by a different module?

I have a class thats being imported in module_x for instantiation, but first I want to override one of the classs methods to include a specific feature dynamically (inside some middleware that runs bef…