Note: For more information about chart legend customization, check out our comprehensive tutorial on Seaborn legends. We’ll use the bbox_to_anchor parameter to define a bounding box for the chart legend. We would like to place the legend outside the countplot. Let’s take a look: Step 7: Add the legend to the countplotĪs can be seen above, the plot legend is overlapping with the top right of the chart. # categorical countplot - show multiple columnsĪx =sns.countplot(x = 'day', data=deliveries, order = day_order, palette='pastel', hue='time')Īx.text (rect.get_x() + rect.get_width() / 2,rect.get_height()+ 0.25,rect.get_height(),horizontalalignment='center', fontsize = 9) We now want to show the usage of the hue parameter of sns.countplot() to achieve a categorical drill down of our delivery data. It’s used for visualizing data and also for presenting the data to your team on a presentation or for yourself for future reference. Looking good: Step 6: Multiple categorical columns in sns countplot Matplotlib is a great data plotting tool. Therefore to avoid this bug, one must always play around with figsize argument in subplot and textent to make the required adjustments. left, bottom, width, and height are in. The issue arises only when using matplotlib.subplot and does not appear for single plot applications. subplot(Position,left bottom width height) creates an axes at the position specified by a four-element vector. # show count (+ annotate)Īx.text (rect.get_x() + rect.get_width() / 2,rect.get_height()+ 0.75,rect.get_height(),horizontalalignment='center', fontsize = 11) When doing subplot, it often scales the size of last panel differently compared to the rest of panels. Matplotlib subplot size code#Here’s a simple code that uses plt.text() to annotate the count values on top of our plot. Step 5: Show count in Seaborn countplotsĪ nice addition to our chart would be the ability to show the value count for every bar. # change order x axis + change palleteĭay_order = Ĭountplt, ax = plt.subplots(figsize = (10,7))Īx =sns.countplot(x = 'day', data=deliveries, order = day_order, palette='pastel' ) Ax.set_title('Daily Deliveries',fontsize = 18, fontweight='bold' )Īx.set_ylabel('Delivery count', fontsize = 15)Ĭountplt Step 4: order of x-axis labels in CountplotsĪs you can see above, the current order of the x-axis ticks doesn’t make much sense. One subplot needs to be about three times as wide as the second (same height).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |