Reputation: 347
I'm trying to plot a smoother grid in the background of this grid that's already plotted. This is what I've done so far. The grid follows my major ticks. I'd like this smoother grid to follow the minor ticks. Is this possible?
My code until now:
fig, ax = plt.subplots(figsize = (20,10))
ax.set_xticks(np.arange(0,round(max(datax)+1)))
ax.set_yticks(np.arange(0,round(max(datay)+1),step = 0.1))
ax.minorticks_on()
ax.grid(True)
plt.xlabel("Tensão (V)", fontsize = 14)
plt.ylabel("Corrente (mA)", fontsize = 14)
plt.title("Experimento 2", fontsize = 20)
ax.errorbar(datax,datay,xerr = sigmax, yerr = sigmay, fmt = ',')
ax.set(xlim= -1, ylim = 0)
P.S.: would you guys organize this code differently? I think it's a complete mess.
i want my grids to look like this this is how they are now
Upvotes: 1
Views: 272
Reputation: 16720
What you want is the linestyle
keyword argument for grid
, along with the linewidth
keyword argument.
Here's how you can use dotted lines for your grid, with thinner lines for the minor ticks:
ax.grid(True, which='major', linestyle=':', linewidth=1, color="black")
ax.grid(True, which='minor', linestyle=':', linewidth=0.5, color="black")
Here's the output (I used faked data since you did not provide a MWE):
You can fiddle with the linewidth
parameter to have the lines appear thinner, or on the color
to make them fainter.
You can also try other linestyles out, like dashed (linestyle='--'
).
Upvotes: 1