Control the distance between the grid in the marine

I would like to change the distance between the horizontal grid lines on the chart of marine origin. I tried to set the style without luck:

seaborn.set_style("whitegrid", {
    "ytick.major.size": 0.1,
    "ytick.minor.size": 0.05,
    'grid.linestyle': '--'
 })

bar(range(len(data)),data,alpha=0.5)
plot(avg_line)

Grid lines are set automatically if I try to override the tick size

enter image description here

Any suggestions? Thanks!

+7
source share
2 answers

You can set the exact checkmark locations later, and they will draw a grid in these places.

The best way to do this is to use MultpleLocatorfrom a module matplotlib.ticker.

For example:

import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker

sns.set_style("whitegrid", {'grid.linestyle': '--'})

fig,ax = plt.subplots()
ax.bar(np.arange(0,50,1),np.random.rand(50)*0.016-0.004,alpha=0.5)

ax.yaxis.set_major_locator(ticker.MultipleLocator(0.005))

plt.show()

enter image description here

+6
source

The OP asked about the change in distance between ticks in Siborn.

Seaborn , Axes, , Axes matplotlib. :

import matplotlib.pyplot as plt
import seaborn as sns
import statsmodels.api as sm
from matplotlib.ticker import MultipleLocator

df = sm.datasets.get_rdataset("Guerry", "HistData").data

ax = sns.scatterplot('Literacy', 'Lottery', data=df)

ax.yaxis.set_major_locator(MultipleLocator(10))
ax.xaxis.set_major_locator(MultipleLocator(10))

plt.show()

, Seaborn, FacetGrid, , . Axes numy FacetGrid.axes.

import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib.ticker import MultipleLocator

tips = sns.load_dataset("tips")
g = sns.lmplot(x="total_bill", y="tip", hue="smoker", data=tips, )

g.axes[0][0].yaxis.set_major_locator(MultipleLocator(3))

. g - FacetGrid, dtype = object, AxesSubplot matplotlib.

FacetGrid, , .

0

Source: https://habr.com/ru/post/1614586/


All Articles