Python TypeError:float()参数必须是字符串或数字,而不是';SingleBlockManager';

Python TypeError:float()参数必须是字符串或数字,而不是';SingleBlockManager';,python,matplotlib,Python,Matplotlib,如果您有任何意见,我将不胜感激。我以前能够使用此代码获取图像,但现在通过我的工作,它给了我这个错误。有没有办法解决这个问题?也许是因为最近升级了matplotlib 我正在使用的代码 import pandas as pd import numpy as np np.random.seed(12345) df = pd.DataFrame([np.random.normal(32000,200000,3650), np.random.normal(4300

如果您有任何意见,我将不胜感激。我以前能够使用此代码获取图像,但现在通过我的工作,它给了我这个错误。有没有办法解决这个问题?也许是因为最近升级了matplotlib

我正在使用的代码

import pandas as pd
import numpy as np
np.random.seed(12345)
df = pd.DataFrame([np.random.normal(32000,200000,3650), 
                   np.random.normal(43000,100000,3650), 
                   np.random.normal(43500,140000,3650), 
                   np.random.normal(48000,70000,3650)], 
                  index=[1992,1993,1994,1995])
import matplotlib as mpl
import matplotlib.pyplot as plt
import scipy.stats as ss
%matplotlib notebook
n = df.shape[1]
year_means = df.mean(axis=1)
year_std = df.std(axis=1)/(np.sqrt(n))
yerr = year_std * 1.96
y= 37000
norm = mpl.colors.Normalize(vmin=-1.96,vmax=1.96)
cmap = mpl.cm.get_cmap('seismic')
colors = pd.DataFrame([])
colors['intensity'] = norm((year_means-y) / year_std)
colors['color'] = [cmap(x) for x in colors['intensity']]
plt.figure()
bar_plot = plt.bar(range(df.shape[0]), year_means, yerr = yerr, color = colors['color']);
hoz_line = plt.axhline(y=y, color='grey', linewidth=2, linestyle = ':');
y_text = plt.text(3.4, y, 'y = %d' %y, bbox=dict(fc='white',ec='k'));
plt.xticks(range(df.shape[0]), df.index, alpha = 0.8);
我收到的错误消息
TypeError回溯(最近一次调用)
在()
2 cmap=mpl.cm.get_cmap(‘地震’)
3种颜色=pd.DataFrame([])
---->4种颜色[“强度”]=标准值((年平均值-y)/年标准值)
5种颜色['color']=[cmap(x)表示x的颜色['intensity']]
6 plt.图()
TypeError:float()参数必须是字符串或数字,而不是“SingleBlockManager”

我能够修复。显然,在matplotlib 2.2中,您不能再使用数据帧调用matplotlib.colors.Normalize。使用我更新的第4行中的值

colors['intensity'] = norm(((year_means-y) / year_std).values)
colors['intensity'] = norm(((year_means-y) / year_std).values)