- 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 put xtick labels in a box matplotlib?
To put xtick labels in a box, we can take the following steps
Steps
Create a new figure or activate an existing figure.
Get the current axis of the figure.
Set the left and bottom position of the axes.
Set the position of the spines, i.e., bottom and left.
To put xtick labels in a box, iterate the ticklabels and use set_bbox() method.
To display the figure, use Show() method.
Example
import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True plt.figure() ax = plt.gca() ax.xaxis.set_ticks_position('bottom') ax.yaxis.set_ticks_position('left') ax.spines['bottom'].set_position(('data', 0)) ax.spines['left'].set_position(('data', 0)) for label in ax.get_xticklabels(): label.set_fontsize(12) label.set_bbox(dict(facecolor='red', edgecolor='black', alpha=0.7)) plt.show()
Output
It will produce the following output −
- Related Articles
- Rotate xtick labels in Seaborn boxplot using Matplotlib
- How can I rotate xtick labels through 90 degrees in Matplotlib?
- How can I make the xtick labels of a plot be simple drawings using Matplotlib?
- How to center labels in a Matplotlib histogram plot?
- How to rotate tick labels in a subplot in Matplotlib?
- How to change the separation between tick labels and axis labels in Matplotlib?
- How to plot a Bar Chart with multiple labels in Matplotlib?
- How to put labels on a scatterplot that is created plot function in R?
- How to set NetworkX edge labels offset in Matplotlib?
- How to put a title for a curved line in Python Matplotlib?
- How to avoid overlapping of labels & autopct in a Matplotlib pie chart?
- How to better rasterize a plot without blurring the labels in matplotlib?
- How to add group labels for bar charts in Matplotlib?
- How to show tick labels on top of a matplotlib plot?
- How do I put a circle with annotation in matplotlib?

Advertisements