![](/img/trans.png)
[英]module 'matplotlib.pyplot' has no attribute 'patches'
[英]module 'matplotlib.pyplot' has no attribute 'xaxis'
所以我對 Python 很陌生,我遇到了以下問題:我想顯示一個箱線圖,但每次我試圖命名軸或 yaxis 時,我都會收到以下錯誤:AttributeError: module 'matplotlib.pyplot ' 沒有屬性 'xaxis' 我會很感激一些幫助,因為我不知道是什么原因造成的。 除了錯誤之外,箱線圖確實顯示正確。
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()
您可能正在尋找的是
plt.xlabel('X - axis')
plt.ylabel('Y - axis')
該錯誤告訴您該屬性不存在,因此您無法訪問 plt.xaxis
這是一個可重現的例子
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");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.