Set gridline transparency with ax.tick_params(grid_alpha=0.35). The grid_alpha value ranges from 0 (transparent) to 1 (opaque). Enable the grid separately with ax.grid(True) if it is not already visible.
Set gridline transparency with tick_params
Pass grid_alpha to an Axes object’s tick_params method. This example sets translucent gridlines on both axes’ major ticks:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([0, 1, 2], [1, 3, 2])
ax.grid(True)
ax.tick_params(axis='both', which='major', grid_alpha=0.35)
plt.show()
grid_alpha is a floating-point opacity value: 0 is transparent and 1 is opaque. Matplotlib’s Axes.tick_params reference for Matplotlib 3.6.1 uses grid_alpha=0.5 as an example.
Choose which gridlines to affect
tick_params defaults to axis='both' and which='major'. Narrow the scope by selecting an axis, tick group, or both:
#1 Best Overall
axis='x'oraxis='y'limits the change to that axis.which='minor'targets minor ticks;which='both'targets major and minor ticks.
For example, this targets gridlines associated with both major and minor x-axis ticks:
ax.tick_params(axis='x', which='both', grid_alpha=0.35)
What else does tick_params change?
The method can style ticks, tick labels, and gridlines. Properties you do not specify remain unchanged unless you pass reset=True; setting only grid_alpha does not reset other tick styling.
Rank #2
For reusable styling across plots, Matplotlib’s matplotlibrc configuration includes base grid color, linestyle, linewidth, and alpha settings. Its current main-branch file lists a base grid.alpha of 1.0, while major and minor alpha entries are None and inherit the base setting. These are moving-branch values, so check the configuration for the Matplotlib release you use rather than treating them as universal defaults.
Alternative: set alpha with ax.grid
If you are configuring the grid itself rather than tick appearance, use ax.grid(alpha=0.35). The Axes.grid reference documents alpha as a line property and says that supplying keyword arguments makes the grid visible.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware match| API | Best fit | Scope and visibility |
|---|---|---|
ax.tick_params(..., grid_alpha=...) |
Styling gridlines alongside tick or tick-label properties | Choose axis and tick group with axis and which; grid visibility may need to be enabled separately. |
ax.grid(alpha=...) |
Directly configuring gridlines | Keyword arguments make the grid visible; the method does not use tick_params‘s axis and tick-group selectors. |
The two APIs are not mutually exclusive: use the one that best matches the surrounding code.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Version considerations
The detailed tick_params reference cited here is for Matplotlib 3.6.1. The implementation source and configuration cited above track the moving main branch, and the documentation reviewed does not establish the first release that supported grid_alpha or confirm behavior across every version. If the argument is rejected by an older installation, consult that installed version’s API reference.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




