- 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 change a table's fontsize with matplotlib.pyplot?
To change a table's fontsize with matplotlib, we can use set_fontsize() method.
Steps
- Create a figure and a set of subplots, nrows=1 and ncols=1.
- Create random data using numpy.
- Create columns value.
- Make the axis tight and off.
- Initialize a variable fontsize to change the font size.
- Set the font size of the table using set_font_size() method.
- To display the figure, use show() method.
Example
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig, axs = plt.subplots(1, 1) data = np.random.random((10, 3)) columns = ("Column I", "Column II", "Column III") axs.axis('tight') axs.axis('off') the_table = axs.table(cellText=data, colLabels=columns, loc='center') the_table.auto_set_font_size(False) the_table.set_fontsize(10) plt.show()
Output
Advertisements