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