- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to better rasterize a plot without blurring the labels in matplotlib?
To rasterize a plot in a bettery way without blurring the labels in matplotlib, we can take the following steps.
Steps
Set the figure size and adjust the padding between and around the subplots.
Create a figure and a set of subplots.
Axis 0 – Fill the area between the curve with alpha and rasterized=False.
Add text to the axes.
Axis 1 – Fill the area between the curve with alpha and rasterized=True.
Add text to the axes.
Axes 2 and 3 – Fill the area between the curve without alpha and rasterized=True and False, respectively.
Add text to the axes.
To display the figure, use Show() method.
Example
import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig, axes = plt.subplots(nrows=4, sharex=True) axes[0].fill_between(np.arange(1, 10), 1, 2, zorder=-1, alpha=0.2, rasterized=False) axes[0].text(5, 1.5, "Label 1", ha='center', va='center', fontsize=25, zorder=-2, rasterized=True) axes[1].fill_between(np.arange(1, 10), 1, 2, zorder=-1, alpha=0.2, rasterized=True) axes[1].text(5, 1.5, "Label 2", ha='center', va='center', fontsize=25, zorder=-2, rasterized=True) axes[2].fill_between(np.arange(1, 10), 1, 2, zorder=-1, rasterized=True) axes[2].text(5, 1.5, "Label 3", ha='center', va='center', fontsize=25, zorder=-2, rasterized=True) axes[3].fill_between(np.arange(1, 10), 1, 2, zorder=-1, rasterized=False) axes[3].text(5, 1.5, "Label 4", ha='center', va='center', fontsize=25, zorder=-2, rasterized=True) plt.show()
Output
It will produce the following output −
Observe that, since we have not used any "alpha" on axes 2 and 3, the labels are not visible.
- Related Articles
- How to center labels in a Matplotlib histogram plot?
- How to plot a Bar Chart with multiple labels in Matplotlib?
- How to show tick labels on top of a matplotlib plot?
- How to create correlation matrix plot without variables labels in R?
- How to build colorbars without attached plot in matplotlib?
- How to change the color of the axis, ticks and labels for a plot in matplotlib?
- Getting empty tick labels before showing a plot in Matplotlib
- How to remove or hide X-axis labels from a Seaborn / Matplotlib plot?
- How to move labels from bottom to top without adding "ticks" in Matplotlib?
- How to remove a frame without removing the axes tick labels from a Matplotlib figure in Python?
- How to hide axes but keep axis-labels in 3D Plot with Matplotlib?
- Plot 3D bars without axes in Matplotlib
- How can I make the xtick labels of a plot be simple drawings using Matplotlib?
- How to put xtick labels in a box matplotlib?
- How to change the separation between tick labels and axis labels in Matplotlib?

Advertisements