-
用plt画直方图时,在hist这句话报错 ValueError: max must be larger than min in range parameter.
n, bins, patches = plt.hist(x,num_bins, facecolor=plt.rcParams['axes.color_cycle'][2], alpha=0.5,edgecolor='black',linestyle='-',linewidth=1)
后来发现是由于读取的csv文件中存在NaN值造成的。因为之前对它进行过增加数据行数,但是恢复原值后没有彻底删除掉所增加的行,而只是把值删除了,所以会报错。 -
plt保存图片时,生成的svg图片下边少了一条,显示不完全,x轴的label只显示了一半:
解决方法:
plt.savefig('D:\\weights_a.svg',format='svg' ,bbox_inches='tight') #保存为svg格式,再用inkscape转为矢量图emf后插入word中 bbox使保存图片时没白边还能显示完全
加bbox这个参数即可。
3.import时报错:/home/heyintao/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:7: UserWarning:
This call to matplotlib.use() has no effect because the backend has already
been chosen; matplotlib.use() must be called before pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.
源代码为:
import matplotlib.pyplot as plt
import matplotlib
matplotlib.use('TkAgg')
修改为: 即可。
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt