1

So I'm very new to Python and I'm having the following issue: I want to display a boxplot but everytime I'm trying to name the axis or yaxis I'm getting the following error: AttributeError: module 'matplotlib.pyplot' has no attribute 'xaxis' I would appreciate some help as I have no idea whats causing this. Other than the error, the boxplot does show correctly.

import pandas as pd
import matplotlib.pyplot as plt
myFile = pd.read_csv("myFile.csv", sep=";")
data_to_plot = [myFile.Class_1,myFile.Class_2]
plt.boxplot(data_to_plot)
plt.xaxis("X - Axis")
plt.yaxis("Y - Axis")
plt.show()
2
  • Do you mind to provide a mcve? Commented Apr 21, 2020 at 1:24
  • pandas already include matplotlib funcionalities. In my answer you got a pandas only solution. Commented Apr 21, 2020 at 3:08

2 Answers 2

3

What you're probably looking for is

plt.xlabel('X - axis')
plt.ylabel('Y - axis')

The error is telling you that the attribute doesn't exist and so you can't access plt.xaxis

Sign up to request clarification or add additional context in comments.

1 Comment

I tried that, it gives me "TypeError: 'str' object is not callable" and pointing to the newly inserted lines.
0

Here a reproducible example

import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.randn(10, 4),
                  columns=['Col1', 'Col2', 'Col3', 'Col4'])
boxplot = df.boxplot(column=['Col1', 'Col2', 'Col3'])
boxplot.set_xlabel("X - axis")
boxplot.set_ylabel("Y - axis");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.