I'm trying to define a matplotlib style file (.mplstyle) to only show horizontal gridlines. I know I can do it in python with
fig, ax = plt.subplots()
ax.yaxis.grid(True)
but I want to do it in the mplstyle file. The classic.mplstyle file has the option axes.grid.axis: both
set. I tried changing this to axes.grid.axis: y
, but this doesn't seem to change anything.
Is it possible to do this in a style file?
EDIT:
An attempt at getting this to work:
%matplotlib inline
import pandas as pd
import matplotlib.pyplot as plt
month = ['Jan', 'Feb', 'Mar', 'Apr']
volume = [1, 2, 3, 4]
plt.style.use('https://gist.githubusercontent.com/luisdelatorre012/b36899e6dca07d05e73aca80eceb3098/raw/43ae73605b5e33dfc3f0d7e5d423ff997fc8325c/tiny.mplstyle')
d = pd.DataFrame({'Month': month, 'Volume': volume})
fig, ax = plt.subplots()
b = d.plot(kind='bar', y="Volume", x="Month", ax=ax)
plt.title('Title')
plt.show()
The file tiny.mplstyle contains
axes.grid.axis: y
axes.grid: True
and nothing else.
This is the result:
Use matplotlib. axis. YAxis. grid() to only plot horizontal gridlines in a graph.
By default, Matplotlib does not display gridlines on plots. However, you can use the matplotlib. pyplot. grid() function to easily display and customize gridlines on a plot.
You need to turn the grid on as well,
import matplotlib.pyplot as plt
plt.rcParams["axes.grid.axis"] ="y"
plt.rcParams["axes.grid"] = True
or in the matplotlibrc file:
axes.grid.axis : y
axes.grid : True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With