matplotliblabelxticks

How to stop x tick labels from crossing x axis?


My x tick labels are crossing the x-axis into the chart area and I don't want them to, an example:

enter image description here

Another oddity is my x axis ticks stopped showing.
I've tried:

But the above did not solve my problem. What should I try next?

Code used to create chart:

my_figure = plt.figure(**{'dpi': 100.0,
                          'edgecolor': 'black',
                          'facecolor': 'black',
                          'figsize': (8.0, 6.0),
                          'linewidth': 1.0})
ax = my_figure.add_subplot(111)
ax.bxp(**{'boxprops': {'alpha': 0.8, 'facecolor': 'C0'},
          'bxpstats': [{'label': 'obs5',
                        'mean': 74.00224000000001,
                        'med': 74.004,
                        'q1': 73.996,
                        'q3': 74.009,
                        'whishi': 73.984,
                        'whislo': 74.014}],
          'capprops': {'color': 'C0'},
          'patch_artist': True,
          'positions': [0],
          'showfliers': False,
          'vert': False,
          'whiskerprops': {'color': 'C0'},
          'widths': 0.5,
          'zorder': 1.0})
ax.spines['left'].set_visible(False)
ax.spines['bottom'].set_visible(True)
ax.tick_params(axis='x', which='major', **{'bottom': False,
                                           'color': 'white',
                                           'direction': 'inout',
                                           'length': 3.0,
                                           'pad': 7.0,
                                           'top': False,
                                           'width': 1.0,
                                           'zorder': 1.0})
ax.tick_params(axis='x', which='major', labelbottom=True)
ax.set_xticks(ticks=ax.get_xticks(minor=False),
              labels=['73.980', '73.985', '73.990', '73.995', '74.000', '74.005', '74.010', '74.015', '74.020'],
              minor=False,
              **{'alpha': 1.0,
                 'color': 'white',
                 'fontfamily': 'serif',
                 'fontsize': 'small',
                 'fontstretch': 'condensed',
                 'fontstyle': 'oblique',
                 'fontvariant': 'small-caps',
                 'fontweight': 'light',
                 'horizontalalignment': 'center',
                 'linespacing': 2.0,
                 'multialignment': 'center',
                 'rotation': 45.0,
                 'snap': True,
                 'verticalalignment': 'center'})
ax.xaxis.set_minor_formatter(plt.NullFormatter())
plt.show()

Solution

  • Two things to change: