simple barplot with orient='v' - unsupported operand type(s) for /: 'str' and 'long'
See original GitHub issueSame error as closed issue https://github.com/mwaskom/seaborn/issues/578? Recording incase #578 won’t apply to barplots. Code as follows. Replacing orient=‘h’ works.
import pandas as pd
import seaborn as sns
plt.close('all')
zeros=90
nonzeros=10
df = pd.DataFrame({'zeros':[zeros], 'total':[zeros+nonzeros], 'label':['Zero']})
sns.set(font_scale=1, style='white')
sns.set_color_codes('pastel')
sns.barplot(x="total", y="label", data=df, orient='v', label="Zero", color="b")
sns.set_color_codes('muted')
ax = sns.barplot(x="zeros", y="label", data=df, orient='v', label="Non-zero", color="b")
plt.show()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-30-ba4f2d6ec1da> in <module>()
8 sns.set(font_scale=1, style='white')
9 sns.set_color_codes('pastel')
---> 10 sns.barplot(x="total", y="label", data=df, orient='v', label="Zero", color="b")
11
12 sns.set_color_codes('muted')
c:\Anaconda2\lib\site-packages\seaborn\categorical.pyc in barplot(x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, orient, color, palette, saturation, errcolor, errwidth, capsize, ax, **kwargs)
2897 estimator, ci, n_boot, units,
2898 orient, color, palette, saturation,
-> 2899 errcolor, errwidth, capsize)
2900
2901 if ax is None:
c:\Anaconda2\lib\site-packages\seaborn\categorical.pyc in __init__(self, x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, orient, color, palette, saturation, errcolor, errwidth, capsize)
1543 order, hue_order, units)
1544 self.establish_colors(color, palette, saturation)
-> 1545 self.estimate_statistic(estimator, ci, n_boot)
1546
1547 self.errcolor = errcolor
c:\Anaconda2\lib\site-packages\seaborn\categorical.pyc in estimate_statistic(self, estimator, ci, n_boot)
1438 statistic.append(np.nan)
1439 else:
-> 1440 statistic.append(estimator(stat_data))
1441
1442 # Get a confidence interval for this estimate
c:\Anaconda2\lib\site-packages\numpy\core\fromnumeric.pyc in mean(a, axis, dtype, out, keepdims)
2940
2941 return _methods._mean(a, axis=axis, dtype=dtype,
-> 2942 out=out, **kwargs)
2943
2944
c:\Anaconda2\lib\site-packages\numpy\core\_methods.pyc in _mean(a, axis, dtype, out, keepdims)
70 ret = ret.dtype.type(ret / rcount)
71 else:
---> 72 ret = ret / rcount
73
74 return ret
TypeError: unsupported operand type(s) for /: 'str' and 'long'
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Seaborn boxplot: TypeError: unsupported operand type(s) for
For seaborn's boxplots it is important to keep an eye on the x-axis and y-axis assignments, when switching between horizontal and vertical ...
Read more >Bar Plots - Quick-R
Create simple and stacked barplots in R with the barplot(height) function, where height is a vector or matrix.
Read more >Seaborn barplot color - miocittadino.it
Write a Python program to create bar plot from a DataFrame. ... type(s) for /: 'str' and 'long' simple barplot with orient='v' -...
Read more >Create Scatter, Line and Bar Charts using Matplotlib
How to Create a Bar Chart using Matplotlib. Bar charts are used to display categorical data. Here is an example of a dataset...
Read more >seaborn.barplot — seaborn 0.12.1 documentation - PyData |
Show point estimates and errors as rectangular bars. A bar plot represents an estimate of central tendency for a numeric variable with the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

If your
yvariable is categorical you can’t draw a vertical barplot.On a side note:
works, but probably not in all reasonable cases. So +1 on not doing any checks 😃