我正在尝试使用Python中的Seaborn创建一个面板图,但是我遇到了一些问题,其中一个问题是旋转x轴标签。
我目前正在尝试使用以下代码:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
vin = pd.Series(["W1","W1","W2","W2","W1","W3","W4"])
word1 = pd.Series(['pdi','pdi','tread','adjust','fill','pdi','fill'])
word2 = pd.Series(['perform','perform','fill','measure','tire','check','tire'])
date = pd.Series(["01-07-2020","01-07-2020","01-07-2020","01-07-2020","01-08-2020","01-08-2020","01-08-2020"])
bigram_with_dates = pd.concat([vin,word1,word2,date], axis = 1)
names = ["vin", "word1","word2","date"]
bigram_with_dates.columns = names
bigram_with_dates['date'] = pd.to_datetime(bigram_with_dates['date'])
bigram_with_dates['text_concat'] = bigram_with_dates['word1'] + "," + bigram_with_dates['word2']
plot_params = sns.FacetGrid(bigram_with_dates, col="date", height=3, aspect=.5, col_wrap = 10,sharex = False, sharey = False)
plot = plot_params.map(sns.countplot, 'text_concat', color = 'c', order = bigram_with_dates['text_concat'])
plot_adjust = plot.fig.subplots_adjust(wspace=0.5, hspace=0.5)
for axes in plot.axes.flat:
axes.set_xticklabels(axes.get_xticklabels(), rotation=90)
我使用这个时出现了一个错误,错误信息如下:
AttributeError: 'NoneType' object has no attribute 'axes'
我认为它的意思是没有返回对象,所以在空对象上设置轴不会有任何作用。
这段代码在其他SO帖子中似乎有效,但我似乎无法让它正常工作。
如果您有任何关于我做错了什么的建议,将不胜感激。
谢谢, Curtis
g
是什么?不应该是plot
吗? - Nicolas Gervais