I am trying to draw a barplot with bars with no borders. By default bars has thin black borders. In the devlopment version (0.6) of Seaborn, I could pass kwargs (linewidth
, edgecolor
) to pyplot.bar()
via seaborn.barplot()
, but in the current version (0.5.1) this feature seems not yet available. Looking at the returned AxesSubplot
object, I could not find the way to set the line width to zero, or the color to fully transparent, although it has many methods, so I still hope there is a way to achieve this.
import matplotlib.pyplot as plt
import seaborn as sns
fig, ax = plt.subplots()
ax = sns.barplot(data = data, x = 'var1', color = '#007b7f')
fig.tight_layout()
fig.savefig('fig.pdf')
The border-color shorthand CSS property sets the color of an element's border.
The color attribute is used to set the color of the bars(maroon in this case). plt. xlabel(“Courses offered”) and plt. ylabel(“students enrolled”) are used to label the corresponding axes.
It has a parameter called figsize which takes a tuple as an argument that contains the height and the width of the plot. It returns the figure and the array of axes. While calling the seaborn plot we will set the ax parameter equal to the array of axes that was returned by matplotlib. pyplot.
This will work too:
fig, ax = plt.subplots()
ax = sns.barplot(data = data, x = 'var1', color = '#007b7f')
plt.setp(ax.patches, linewidth=0)
After many attempts without success, I asked the question here, and soon I found the solution myself. So here it is: before plotting, the patch.linewidth
parameter can be set with seaborn.set_context()
:
import seaborn as sns
sns.set_context(rc = {'patch.linewidth': 0.0})
ax = sns.barplot(...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With