I am trying to make a nice bar plot, but run into the following issues:
- The horizontal grid lines are in front of the bars, even though I tried all kinds of zorder parameters of
ax.grid
. How can I get the grid to the back? - The tight layout is not tight. I tried
fig.tight_layout()
andplt.tight_layout()
. How can I crop the picture automatically on all sides? - Is there a way to position the xTick-text, so that each "longText" is aligned with its xTick?
import matplotlib.pyplot as plt
def show_mountains(bins, fortyfive=False):
fig, ax = plt.subplots()
ax.grid(axis='y', zorder=-100, linewidth=0.2)
fig.tight_layout()
xTicks = list(range(len(bins)))
if fortyfive:
plt.xticks(rotation=45)
ax.set_xticks(xTicks)
ax.set_xticklabels(["longText"]*len(bins), fontsize=13)
plt.bar(xTicks, bins, width=0.65, color="#6186f1")
plt.tight_layout()
plt.close()
domain_bins = [52, 47, 36, 15, 14, 11, 18]
show_mountains(domain_bins, True)