How do I get rid of the dotted line on the x-axis of a Pandas / Matplotlib plot?

EDIT: This line has been removed in Pandas ( https://github.com/pydata/pandas/issues/9088 ).

I am drawing a bar using a plot

Pandas function . It keeps appearing with a weird dotted line right above the x-axis.

These are not ticks or the x-axis that I got rid of:

plt.tick_params(axis="both", which="both", bottom="off", top="off",  
        labelbottom="on", left="off", right="off", labelleft="on")  
ax.spines["bottom"].set_visible(False)

      

But I still have this dotted line on the x-axis! What is this line even if it is not ticking or the x-axis?

example plot

+3


source to share


1 answer


pandas adds a dashed horizontal line on the axis of the strokes. There pandas/tools/plotting.py

is a line in BarPlot._post_plot_logic

(line 1842 in my version):

ax.axhline(0, color='k', linestyle='--')

      

This is clearly not documented and there seems to be no way to stop this. Even worse, the plot does not contain a link to the line, so there is no clear way to safely remove it. If the barcode is "simple" this will work:



ax.get_lines()[0].set_visible(False)

      

This only works because, in a regular line font, this is the only line artist in the plot. If you are doing anything else that adds other lines to the plot, it can be difficult to determine which one is the axis you want to remove.

+4


source







All Articles