bar-chart
Matplotlib, horizontal bar chart (barh) is upside-down
I believe the joint wrong order of groups and subgroups boils down to a single feature: that the y axis increases upwards, as in a usual plot. Try reversing the y axis of your axes as in this pandas-less example: import numpy as np import matplotlib.pyplot as plt x = range(5) y = np.random.randn(5) # … Read more
Matplotlib bar graph x axis won’t plot string values
Your question has nothing to do with an SQL query, it is simply a means to end. What you are really asking is how to change the text labels on a bar chart in pylab. The docs for the bar chart are useful for customizing, but to simply change the labels here is a minimal … Read more
How to increase the space between bar plot bars
Try replace plt.bar(range(len(my_dict)), my_dict.values(), align=’center’) with plt.figure(figsize=(20, 3)) # width:20, height:3 plt.bar(range(len(my_dict)), my_dict.values(), align=’edge’, width=0.3) The option align=’edge’ will eliminate white space on the left of the bar chart. And width=0.3 sets the bars’ width smaller size than the default value. The bars spacing will be adjusted accordingly. For the labels along x-axis, they should … Read more
Change bar color according to hue name
A. using a list of colors The easiest solution to make sure to have the same colors for the same categories in both plots would be to manually specify the colors at plot creation. # First bar plot ax = sns.barplot(data=a, x=’Scenario’, y=’Duration’, hue=”Program”, ci=None, palette=[“C0”, “C1”, “k”]) # … # Second bar plot ax2 … Read more
Order categories by count in a seaborn 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
Barchart with vertical ytick labels
Do you mean something like this: >>> from matplotlib import * >>> plot(xrange(10)) >>> yticks(xrange(10), rotation=’vertical’) ? In general, to show any text in matplotlib with a vertical orientation, you can add the keyword rotation=’vertical’. For further options, you can look at help(matplotlib.pyplot.text) The yticks function plots the ticks on the y axis; I am … Read more