Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rid of grid lines when plotting with Seaborn + Pandas with secondary_y

I'm plotting two data series with Pandas with seaborn imported. Ideally I would like the horizontal grid lines shared between both the left and the right y-axis, but I'm under the impression that this is hard to do.

As a compromise I would like to remove the grid lines all together. The following code however produces the horizontal gridlines for the secondary y-axis.

import pandas as pd import numpy as np import seaborn as sns   data = pd.DataFrame(np.cumsum(np.random.normal(size=(100,2)),axis=0),columns=['A','B']) data.plot(secondary_y=['B'],grid=False) 

gridlines that I want to get rid of

like image 665
Artturi Björk Avatar asked Nov 11 '14 15:11

Artturi Björk


People also ask

How do I remove gridlines from a plot in Python?

Convert the image from one color space to another. To remove grid lines, use ax. grid(False).

How do you set the dark grid in seaborn plots?

Set the background to be darkgrid: Darkgrid appear on the sides of the plot on setting it as set_style('darkgrid'). palette attribute is used to set the color of the bars. It helps to distinguish between chunks of data.

How do you remove gridlines in seaborn plot?

To get rid of gridlines, use grid=False. To display the figure, use show() method.


1 Answers

You can take the Axes object out after plotting and perform .grid(False) on both axes.

# Gets the axes object out after plotting ax = data.plot(...)  # Turns off grid on the left Axis. ax.grid(False)  # Turns off grid on the secondary (right) Axis. ax.right_ax.grid(False) 
like image 93
Luan Nguyen Avatar answered Sep 20 '22 14:09

Luan Nguyen