I want to get both horizontal and vertical grid lines on my plot but only the horizontal grid lines are appearing by default. I am using a pandas.DataFrame
from an sql query in python to generate a line plot with dates on the x-axis. I'm not sure why they do not appear on the dates and I have tried to search for an answer to this but couldn't find one.
All I have used to plot the graph is the simple code below.
data.plot() grid('on')
data is the DataFrame which contains the dates and the data from the sql query.
I have also tried adding the code below but I still get the same output with no vertical grid lines.
ax = plt.axes() ax.yaxis.grid() # horizontal lines ax.xaxis.grid() # vertical lines
Any suggestions?
Locate minor locator on the axes. Use grid() method to make minor grid lines. To display the figure, use show() method.
You may need to give boolean arg in your calls, e.g. use ax.yaxis.grid(True)
instead of ax.yaxis.grid()
. Additionally, since you are using both of them you can combine into ax.grid
, which works on both, rather than doing it once for each dimension.
ax = plt.gca() ax.grid(True)
That should sort you out.
plt.gca().xaxis.grid(True)
proved to be the solution for me
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