【发布时间】:2014-07-08 00:06:03
【问题描述】:
我对 python 很陌生,所以我正在阅读 nltk 书。我也在尝试熟悉操作图形和绘图。我绘制了一个条件频率分布,我想从移除顶部和左侧的刺开始。这就是我所拥有的:
import nltk
import sys
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.pyplot import show
from nltk.corpus import state_union
#cfdist1
cfd = nltk.ConditionalFreqDist(
(word, fileid[:4])
for fileid in state_union.fileids()
for w in state_union.words(fileid)
for word in ['men', 'women', 'people']
if w.lower().startswith(word))
cfd.plot()
for loc, spine in cfd.spines.items():
if loc in ['left','bottom']:
spine.set_position(('outward',0)) # outward by 0
elif loc in ['right','top']:
spine.set_color('none') # don't draw spine
else:
raise ValueError('unknown spine location: %s'%loc)
我收到以下错误:
AttributeError: 'ConditionalFreqDist' object has no attribute 'spines'
有没有办法操纵条件频率分布?谢谢!
【问题讨论】:
-
正在删除您的 cmets 吗?您遇到的问题是因为使用 draw() 需要交互模式,并且看起来您没有使用交互模式。我已经更新了我的答案。
标签: python matplotlib plot frequency-distribution