- 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 get XKCD font working in Matplotlib?
To get xkcd font working, we can use plt.xkcd() to turn on sketch-style drawing mode.
Steps
- Set the figure size and adjust the padding between and around the subplots.
- Create x and y data points using numpy.
- Use plt.xkcd() to turn on sketch-style drawing mode.
- Create a new figure or activate an existing figure.
- Add an axis to the figure as part of a subplot arrangement.
- Plot x and y data points using plot() method.
- Place a text and title on the plot.
- To display the figure, use show() method.
Example
from matplotlib import pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.arange(10) y = np.sin(x) plt.xkcd() fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax.plot(x, y) ax.text(4, 4, '(4, 4)', size=16) plt.title('Y=sin(x)') plt.show()
Output
Advertisements