1

How do I align the first bar with the x-label CI? It is too left. To be even more pickier, the rest of the bars are shifted to the right as well. How can I center all of them?

bar chart

My code looks like this:

colors = ["coral", "sea blue"]
g = sns.FacetGrid(data=c_obs_00_pd, size=7, aspect=1.5)
g.map(sns.barplot, "Name", '% of Significant T Test', "Location", palette=sns.xkcd_palette(colors), order=['CI', '20%, Small', '20%, Large', '50%, Small', '50%, Large'])
g.map(plt.axhline, y=5.6, color="k", ls='--', lw="3")
loading_patch = mpl.patches.Patch(color='#fc5a50', label='Loading')
threshold_patch = mpl.patches.Patch(color='#047495', label='Threshold')
plt.legend(handles=[loading_patch, threshold_patch], loc='upper left', ncol=1, fontsize=14)
plt.title("Cancelout Simulation", fontsize=18)
plt.ylabel("Percent of Significant t-Tests", fontsize=18, labelpad=25)
plt.xlabel("Conditions - Latent Means Simulated as Equal", fontsize=18, labelpad=20)
plt.grid(b=True, which='minor', color='k', axis='y', linestyle='-', alpha=0.1)
plt.tick_params(axis='both', which='major', labelsize=16)
plt.minorticks_on()
plt.savefig('Cancelout-% of Sig t-Test in Equal Latent Mean.png', dpi=75)
joelostblom
  • 43,590
  • 17
  • 150
  • 159
Steven Chen
  • 397
  • 1
  • 6
  • 19
  • 2
    Your hue variable has three levels but only two are shown in the plot. – mwaskom Mar 09 '17 at 14:08
  • 3
    In other words, they are centered, there just isn't any data in the left-most bars – Paul H Mar 09 '17 at 17:25
  • The first hue condition is only present at the CI level and the second two are present at all other levels. The manual legend obscures this. I'm not sure exactly what your data look like or what you're trying to show, but that's the answer to your narrow question. – mwaskom Mar 09 '17 at 19:07
  • Does this answer your question? [Centre bars in barplots if category is missing in hue](https://stackoverflow.com/questions/69152962/centre-bars-in-barplots-if-category-is-missing-in-hue) – My Work Jan 19 '22 at 12:08

1 Answers1

3

As indicated in the comments, the reason the bars appear to be off-center is because you have one hue level that is not showing up in the plot, i.e. there is no data in the left most bars.

joelostblom
  • 43,590
  • 17
  • 150
  • 159