

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 produce a barcode in Matplotlib?
To produce a barcode in Matplotlib, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Make a list of binary numbers, i.e., 0s and 1s.
- Create a new figure or activate an existing figure with dpi=100
- Add an axes to the figure.
- Turn off the axes.
- Use imshow() method to plot the data from step 2.
- To display the figure, use show() method.
Example
import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True code = np.array([ 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1]) fig = plt.figure(dpi=100) ax = fig.add_axes([0, 0, 1, 1]) ax.set_axis_off() ax.imshow(code.reshape(1, -1), cmap='binary', aspect='auto', interpolation='nearest') plt.show()
Output
- Related Questions & Answers
- How to produce documentation for Python functions?
- How to produce your content hard to copy
- How to produce group subtotals and a grand total in Oracle?
- Barcode Scanning in Android using Kotlin?
- Using operations to produce desired results in JavaScript
- How can MySQL produce the output in a vertical format rather than tabular format?
- What are the differences between Fastag and Barcode?
- What are the differences between Barcode and NFC?
- What are the differences between RFID and Barcode?
- How to produce group subtotals for all combinations of the dimensions specified in Oracle?
- How to plot a circle in Matplotlib?
- How to animate a pcolormesh in Matplotlib?
- How to label a patch in matplotlib?
- What are the differences between Fastag, Barcode and NFC?
- What are the differences between Barcode and QR Code?
Advertisements