Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk2 min

How to Set Matplotlib Grid Alpha with tick_params in Python

Set Matplotlib gridline transparency with tick_params(grid_alpha=...), and control whether it affects x or y axes and major or minor ticks.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • axis='x' or axis='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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.Support on Ko-Fi

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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.