
- Matplotlib - Home
- Matplotlib - Introduction
- Matplotlib - Vs Seaborn
- Matplotlib - Environment Setup
- Matplotlib - Anaconda distribution
- Matplotlib - Jupyter Notebook
- Matplotlib - Pyplot API
- Matplotlib - Simple Plot
- Matplotlib - Saving Figures
- Matplotlib - Markers
- Matplotlib - Figures
- Matplotlib - Styles
- Matplotlib - Legends
- Matplotlib - Colors
- Matplotlib - Colormaps
- Matplotlib - Colormap Normalization
- Matplotlib - Choosing Colormaps
- Matplotlib - Colorbars
- Matplotlib - Working With Text
- Matplotlib - Text properties
- Matplotlib - Subplot Titles
- Matplotlib - Images
- Matplotlib - Image Masking
- Matplotlib - Annotations
- Matplotlib - Arrows
- Matplotlib - Fonts
- Matplotlib - Font Indexing
- Matplotlib - Font Properties
- Matplotlib - Scales
- Matplotlib - LaTeX
- Matplotlib - LaTeX Text Formatting in Annotations
- Matplotlib - PostScript
- Matplotlib - Mathematical Expressions
- Matplotlib - Animations
- Matplotlib - Celluloid Library
- Matplotlib - Blitting
- Matplotlib - Toolkits
- Matplotlib - Artists
- Matplotlib - Styling with Cycler
- Matplotlib - Paths
- Matplotlib - Path Effects
- Matplotlib - Transforms
- Matplotlib - Ticks and Tick Labels
- Matplotlib - Radian Ticks
- Matplotlib - Dateticks
- Matplotlib - Tick Formatters
- Matplotlib - Tick Locators
- Matplotlib - Basic Units
- Matplotlib - Autoscaling
- Matplotlib - Reverse Axes
- Matplotlib - Logarithmic Axes
- Matplotlib - Symlog
- Matplotlib - Unit Handling
- Matplotlib - Ellipse with Units
- Matplotlib - Spines
- Matplotlib - Axis Ranges
- Matplotlib - Axis Scales
- Matplotlib - Axis Ticks
- Matplotlib - Formatting Axes
- Matplotlib - Axes Class
- Matplotlib - Twin Axes
- Matplotlib - Figure Class
- Matplotlib - Multiplots
- Matplotlib - Grids
- Matplotlib - Object-oriented Interface
- Matplotlib - PyLab module
- Matplotlib - Subplots() Function
- Matplotlib - Subplot2grid() Function
- Matplotlib - Anchored Artists
- Matplotlib - Manual Contour
- Matplotlib - Coords Report
- Matplotlib - AGG filter
- Matplotlib - Ribbon Box
- Matplotlib - Fill Spiral
- Matplotlib - Findobj Demo
- Matplotlib - Hyperlinks
- Matplotlib - Image Thumbnail
- Matplotlib - Plotting with Keywords
- Matplotlib - Create Logo
- Matplotlib - Multipage PDF
- Matplotlib - Multiprocessing
- Matplotlib - Print Stdout
- Matplotlib - Compound Path
- Matplotlib - Sankey Class
- Matplotlib - MRI with EEG
- Matplotlib - Stylesheets
- Matplotlib - Background Colors
- Matplotlib - Basemap
- Matplotlib - Event Handling
- Matplotlib - Close Event
- Matplotlib - Mouse Move
- Matplotlib - Click Events
- Matplotlib - Scroll Event
- Matplotlib - Keypress Event
- Matplotlib - Pick Event
- Matplotlib - Looking Glass
- Matplotlib - Path Editor
- Matplotlib - Poly Editor
- Matplotlib - Timers
- Matplotlib - Viewlims
- Matplotlib - Zoom Window
- Matplotlib Widgets
- Matplotlib - Cursor Widget
- Matplotlib - Annotated Cursor
- Matplotlib - Buttons Widget
- Matplotlib - Check Buttons
- Matplotlib - Lasso Selector
- Matplotlib - Menu Widget
- Matplotlib - Mouse Cursor
- Matplotlib - Multicursor
- Matplotlib - Polygon Selector
- Matplotlib - Radio Buttons
- Matplotlib - RangeSlider
- Matplotlib - Rectangle Selector
- Matplotlib - Ellipse Selector
- Matplotlib - Slider Widget
- Matplotlib - Span Selector
- Matplotlib - Textbox
- Matplotlib Plotting
- Matplotlib - Line Plots
- Matplotlib - Area Plots
- Matplotlib - Bar Graphs
- Matplotlib - Histogram
- Matplotlib - Pie Chart
- Matplotlib - Scatter Plot
- Matplotlib - Box Plot
- Matplotlib - Arrow Demo
- Matplotlib - Fancy Boxes
- Matplotlib - Zorder Demo
- Matplotlib - Hatch Demo
- Matplotlib - Mmh Donuts
- Matplotlib - Ellipse Demo
- Matplotlib - Bezier Curve
- Matplotlib - Bubble Plots
- Matplotlib - Stacked Plots
- Matplotlib - Table Charts
- Matplotlib - Polar Charts
- Matplotlib - Hexagonal bin Plots
- Matplotlib - Violin Plot
- Matplotlib - Event Plot
- Matplotlib - Heatmap
- Matplotlib - Stairs Plots
- Matplotlib - Errorbar
- Matplotlib - Hinton Diagram
- Matplotlib - Contour Plot
- Matplotlib - Wireframe Plots
- Matplotlib - Surface Plots
- Matplotlib - Triangulations
- Matplotlib - Stream plot
- Matplotlib - Ishikawa Diagram
- Matplotlib - 3D Plotting
- Matplotlib - 3D Lines
- Matplotlib - 3D Scatter Plots
- Matplotlib - 3D Contour Plot
- Matplotlib - 3D Bar Plots
- Matplotlib - 3D Wireframe Plot
- Matplotlib - 3D Surface Plot
- Matplotlib - 3D Vignettes
- Matplotlib - 3D Volumes
- Matplotlib - 3D Voxels
- Matplotlib - Time Plots and Signals
- Matplotlib - Filled Plots
- Matplotlib - Step Plots
- Matplotlib - XKCD Style
- Matplotlib - Quiver Plot
- Matplotlib - Stem Plots
- Matplotlib - Visualizing Vectors
- Matplotlib - Audio Visualization
- Matplotlib - Audio Processing
- Matplotlib Useful Resources
- Matplotlib - Quick Guide
- Matplotlib - Cheatsheet
- Matplotlib - Useful Resources
- Matplotlib - Discussion
Matplotlib - XKCD Style
XKCD style refers to a particular type of comic art and humour inspired by the webcomic "XKCD", created by Randall Munroe. XKCD comics are generally known for their modest drawings, often stick-figure characters, and simple black-and-white artwork. The comic covers a wide range of topics, including science, mathematics, technology, and everyday life, presenting them in a humorous and thought-provoking manner.
XKCD Style in Matplotlib
In Matplotlib, XKCD style refers to a feature that allows you to make plots look like they are hand-drawn with a marker, similar to the style of the XKCD webcomic by Randall Munroe. This means the lines in your plots will appear wobbly and not perfectly straight, giving them a playful and informal look. It is a fun way to visualize your data with a touch of humour or character to your plots.
To draw plots in XKCD style in Matplotlib, you can use the plt.xkcd() function. This function enables the XKCD mode, which transforms subsequent plots to mimic the hand-drawn aesthetic characteristic of XKCD comics.
Basic XKCD Style Plot
A basic XKCD style plot in Matplotlib is a type of graph that adopts the whimsical and hand-drawn appearance inspired by the XKCD webcomic. It gives your plots a playful and informal look with irregular lines, handwritten fonts, and exaggerated features, similar to the style used in XKCD comics.
Example
In the following example, we are creating a simple line plot using XKCD style. The plot shows the relationship between X and Y values −
import matplotlib.pyplot as plt # Enabling the XKCD mode plt.xkcd() # Creating a simple XKCD style plot plt.plot([1, 2, 3, 4], [1, 4, 9, 16], 'b-') plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.title('XKCD Style Plot') plt.show()
Output
Following is the output of the above code −

XKCD Style Scatter Plot
In Matplotlib, the XKCD style scatter plot provides a quirky and hand-drawn look to your data visualization. By enabling XKCD mode with plt.xkcd(), your scatter plot takes on a whimsical appearance, with points resembling doodles drawn by hand. This style adds a fun and informal touch to your scatter plots, making them more engaging and visually interesting.
Example
In here, we are using the XKCD mode to create a scatter plot with "red" points. Each point represents a pair of "X" and "Y" values −
import matplotlib.pyplot as plt # Enabling XKCD mode plt.xkcd() # Creating an XKCD style scatter plot plt.scatter([1, 2, 3, 4], [1, 4, 9, 16], color='r') plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.title('XKCD Style Scatter Plot') plt.show()
Output
Output of the above code is as follows −

XKCD Style Bar Plot
In Matplotlib, an XKCD style bar plot is a type of chart where rectangular bars represent data values. When XKCD mode is enabled with plt.xkcd(), the bars and axes take on a playful and hand-drawn appearance, resembling doodles rather than precise graphical elements.
Bar plots are commonly used to compare categorical data or show the distribution of a dataset across different categories, and the XKCD style adds a fun twist to this traditional chart type.
Example
In the example below, we are using the XKCD mode to create a bar plot with four categories (A, B, C, D) and their corresponding values. We draw the bars in "green" color −
import matplotlib.pyplot as plt # Enabling XKCD mode plt.xkcd() # Creating an XKCD style bar plot plt.bar(['A', 'B', 'C', 'D'], [10, 20, 15, 25], color='g') plt.xlabel('Categories') plt.ylabel('Values') plt.title('XKCD Style Bar Plot') plt.show()
Output
After executing the above code, we get the following output −

XKCD Style Pie Chart
In Matplotlib, an XKCD style pie chart is a graphical representation of data where a circle is divided into slices to show numerical proportions. When XKCD mode is activated with plt.xkcd(), the pie chart takes on a hand-drawn appearance, resembling a sketch rather than a precise diagram. Each slice of the pie appears as if it were drawn by hand.
Pie charts are commonly used to display the composition of a dataset or the distribution of categories, and the XKCD style adds a fun twist to this classic chart type.
Example
Now, we are using the XKCD mode to create a a pie chart displaying the proportions of different categories (A, B, C, D). The "autopct" parameter adds percentage labels to each wedge, while "startangle" sets the starting angle for the first wedge −
import matplotlib.pyplot as plt # Enabling XKCD mode plt.xkcd() # Creating an XKCD style pie chart sizes = [15, 30, 45, 10] plt.pie(sizes, labels=['A', 'B', 'C', 'D'], autopct='%1.1f%%', startangle=140) plt.title('XKCD Style Pie Chart') plt.show()
Output
The output obtained is as shown below −
