- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 can I make the xtick labels of a plot be simple drawings using Matplotlib?
To make xtick labels of a plot be simple drawings using Matplotlib, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Initialize the y position of simple drawings.
- Create a new figure or activate an existing figure using figure() method.
- Add an '~.axes.Axes' to the figure as part of a subplot arrangement using add_subplot()method.
- Plot a line using plot() method.
- Set the X-axis ticks using set_ticks() method.
- Set empty tick labels.
- Add circles and rectangles patches using add_patch() method. Instantiate Circle() and Rectangle() class.
- To display the figure, use show() method.
Example
import matplotlib.pyplot as plt import matplotlib.patches as patches plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True y = -.75 fig = plt.figure() ax = fig.add_subplot(111) ax.plot(range(10)) ax.get_xaxis().set_ticks([2, 4, 6, 8]) ax.get_xaxis().set_ticklabels([]) ax.add_patch(patches.Circle((2, y), radius=.2, clip_on=False, facecolor='red')) ax.add_patch(patches.Circle((4, y), radius=.2, clip_on=False, facecolor='yellow')) ax.add_patch(patches.Rectangle((6 - .1, y - .05), .2, .2, clip_on=False, facecolor='blue')) ax.add_patch(patches.Rectangle((8 - .1, y - .05), .2, .2, clip_on=False, facecolor='green')) plt.show()
Output
- Related Articles
- How can I rotate xtick labels through 90 degrees in Matplotlib?
- Rotate xtick labels in Seaborn boxplot using Matplotlib
- How to put xtick labels in a box matplotlib?
- How can I make a simple 3D line with Matplotlib?
- How to make a simple lollipop plot in Matplotlib?
- How can I make a scatter plot colored by density in Matplotlib?
- Explain how a quiver plot can be built using Matplotlib Python?
- How can a simple bivariate distribution be shown using ‘imshow’ in Matplotlib Python?
- How can I draw inline line labels in Matplotlib?
- How to center labels in a Matplotlib histogram plot?
- How can I plot a confusion matrix in matplotlib?
- How to show tick labels on top of a matplotlib plot?
- How can I plot hysteresis threshold in Matplotlib?
- How can I get the output of a Matplotlib plot as an SVG?
- How do I customize the display of edge labels using networkx in Matplotlib?

Advertisements