1

The below set of code previously worked well and I was able to visualise the boxplot graph well. This code was previously used in another project of mine, and it worked perfectly well. There were no changes done to this piece of code, and it is being reused here.

I have a 'df' dataframe and I am trying to create boxplots to visualise outliers. Unfortunately, the graph doesn't seem to visualise anything. I am not sure what is wrong with my set of code. Could someone please help?

df = pd.DataFrame({'TotalPrice':[1.000, 0.650, 0.0075, 0.0025, 0.200], 'Voltage':[13.47, 13.41, 13.41, 13.41, 13.41], 'ConversionFactor':[934.0, 934.0, 2580.0, 934.0, 934.0], 'Litres':[40.0, 26.0, 3.0, 1.0, 8.0]}) import pandas as pd import numpy as np import matplotlib.pyplot as plt from matplotlib import style import warnings warnings.filterwarnings("ignore") %matplotlib inline %pylab inline df = pd.read_csv('dataset.csv') fig, ax = plt.subplots(1,4, figsize = (8, 4)) ax[0].boxplot(df.TotalPrice) ax[1].boxplot(df.Voltage) ax[2].boxplot(df.ConversionFactor) ax[3].boxplot(df.Litres); 

enter image description here

The dataframe sample: enter image description here

5
  • 1
    what does your dataframe look like? Commented Nov 13, 2021 at 16:34
  • Dataframe sample attached. Commented Nov 13, 2021 at 16:42
  • 1
    DO NOT post images of code, data, error messages, etc. - copy or type the text into the question. Please reserve the use of images for diagrams or demonstrating rendering bugs, things that are impossible to describe accurately via text. For more information please see the Meta FAQ entry Why not upload images of code/errors when asking a question? Commented Nov 13, 2021 at 16:45
  • The below set of code previously worked well - define 'previously' Commented Nov 13, 2021 at 17:02
  • When you say previously used in another project -- did this previous project use the same environment, i.e. Jupyter Notebook? This is the crucial bit of information. Commented Nov 13, 2021 at 17:08

2 Answers 2

1

If you change from inline to notebook, and remove your pylab reference, it will work as expected within Jupyter Notebook:

%matplotlib notebook #< not inline # %pylab inline #< this is not needed 
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect answer !
0

You forgot to import df. Your code returns the following error:

Populating the interactive namespace from numpy and matplotlib --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-1-d9ef2c853adf> in <module>() 12 fig, ax = plt.subplots(1,4, figsize = (8, 4)) 13 ---> 14 ax[0].boxplot(df.TotalPrice) 15 ax[1].boxplot(df.Voltage) 16 ax[2].boxplot(df.ConversionFactor) NameError: name 'df' is not defined 

2 Comments

I have already imported the dataframe, my code is now edited.
add plt.show()? I don't know I have no access to your dataframe.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.