Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.8k views
in Technique[技术] by (71.8m points)

jupyter notebook - TypeError: Neither the `x` nor `y` variable appears to be numeric

I am trying to generate a boxplot using seaborn, on jupyter notebook, but I receive this error. This is the simulator along with the jupyter notebook file and results: https://github.com/netreconlab/smartcomp19

Part of the code which results in error:

ax = sns.boxplot(x=['Sensor u2192 Bus','Bus u2192 Gateway'], y=[np.array(ons_tbs)/60, np.array(ons_tbg)/60])
#ax.set_title('(e)');
ax.set_ylabel('Delay (Minutes)')
ax.figure.set_size_inches((10,10))
ax.set_title("Delays for on-route packets")
ax.figure.savefig('e.png', dpi=300)

print("Sensor->Bus 
Mean: {0}, Median: {1}".format(np.mean(ons_tbs)/60, np.median(ons_tbs)/60))
print("Bus->Gateway 
Mean: {0}, Median: {1}".format(np.mean(ons_tbg)/60, np.median(ons_tbg)/60))

TypeError                                 Traceback (most recent call last)
<ipython-input-50-48300710b334> in <module>
----> 1 ax = sns.boxplot(x=['Sensor u2192 Bus','Bus u2192 Gateway'], y=[np.array(ons_tbs)/60, np.array(ons_tbg)/60])
      2 #ax.set_title('(e)');
      3 ax.set_ylabel('Delay (Minutes)')
      4 ax.figure.set_size_inches((10,10))
      5 ax.set_title("Delays for on-route packets")

~/anaconda3/lib/python3.8/site-packages/seaborn/_decorators.py in inner_f(*args, **kwargs)
     44             )
     45         kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
---> 46         return f(**kwargs)
     47     return inner_f
     48 

~/anaconda3/lib/python3.8/site-packages/seaborn/categorical.py in boxplot(x, y, hue, data, order, hue_order, orient, color, palette, saturation, width, dodge, fliersize, linewidth, whis, ax, **kwargs)
   2228 ):
   2229 
-> 2230     plotter = _BoxPlotter(x, y, hue, data, order, hue_order,
   2231                           orient, color, palette, saturation,
   2232                           width, dodge, fliersize, linewidth)

~/anaconda3/lib/python3.8/site-packages/seaborn/categorical.py in __init__(self, x, y, hue, data, order, hue_order, orient, color, palette, saturation, width, dodge, fliersize, linewidth)
    404                  width, dodge, fliersize, linewidth):
    405 
--> 406         self.establish_variables(x, y, hue, data, orient, order, hue_order)
    407         self.establish_colors(color, palette, saturation)
    408 

~/anaconda3/lib/python3.8/site-packages/seaborn/categorical.py in establish_variables(self, x, y, hue, data, orient, order, hue_order, units)
    154 
    155             # Figure out the plotting orientation
--> 156             orient = infer_orient(
    157                 x, y, orient, require_numeric=self.require_numeric
    158             )

~/anaconda3/lib/python3.8/site-packages/seaborn/_core.py in infer_orient(x, y, orient, require_numeric)
   1327     elif require_numeric and "numeric" not in (x_type, y_type):
   1328         err = "Neither the `x` nor `y` variable appears to be numeric."
-> 1329         raise TypeError(err)
   1330 
   1331     else:

TypeError: Neither the `x` nor `y` variable appears to be numeric.

I don't know how to solve this issue, any suggestion would help. Thank you!

question from:https://stackoverflow.com/questions/65944701/typeerror-neither-the-x-nor-y-variable-appears-to-be-numeric

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...