bar-chart
Order categories by count in a countplot
This functionality is not built into seaborn.countplot as far as I know – the order parameter only accepts a list of strings for the categories, and leaves the ordering logic to the user. This is not hard to do with value_counts() provided you have a DataFrame though. For example, import pandas as pd import seaborn … Read more
JFreeChart BarChart -> NO gradient
The problem lies in the BarPainter you are using. The JFreeChart version 1.0.13 default is to use GradientBarPainter which adds a metallic-ish look to the bar. If you want the “old” look the solution is to use the StandardBarPainter. final CategoryPlot plot = chart.getCategoryPlot(); ((BarRenderer) plot.getRenderer()).setBarPainter(new StandardBarPainter()); That should do it. Alternatively, if you want … Read more
How to remove gaps between bars in a bar chart
Add width=1.0 as a keyword argument to bar(). E.g. xs.bar(bar_lefts, bar_heights, width=1.0, facecolor=”black”, edgecolor=”black”). This will fill the bars gaps vertically.
How to change the color of a single bar in a bar plot
Simple, just use .set_color >>> barlist=plt.bar([1,2,3,4], [1,2,3,4]) >>> barlist[0].set_color(‘r’) >>> plt.show() For your new question, not much harder either, just need to find the bar from your axis, an example: >>> f=plt.figure() >>> ax=f.add_subplot(1,1,1) >>> ax.bar([1,2,3,4], [1,2,3,4]) <Container object of 4 artists> >>> ax.get_children() [<matplotlib.axis.XAxis object at 0x6529850>, <matplotlib.axis.YAxis object at 0x78460d0>, <matplotlib.patches.Rectangle object at … Read more
Bar plot with groupby
I think you need add unstack for DataFrame: df.groupby(‘year’).case_status.value_counts().unstack().plot.barh() Also is possible change level: df.groupby(‘year’).case_status.value_counts().unstack(0).plot.barh()