I am trying to create a table using matplotlib in Python.
Here is the code
# -*- coding: utf-8 -*-
import sys
import matplotlib.pyplot as plt
val1 = ["ABC", "CDE", "AEX", "SM12", "AEX", "AEX", "AEX", "AEX", "AEX", "AEX", "AEX", "AEX", "AEX", "ABC", "AEF", "AEF", "SC", "SV", "JAVA", "TBS", "AEF", "AEF", "AEF", "ABC"]
val2 = ["KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "KPG", "LOL"]
val3 = [["" for c in range(24)] for r in range(35)]
def cration_tableau():
creation_of_table = True
fig, ax = plt.subplots()
ax.set_axis_off()
table = ax.table(
cellText = val3,
rowLabels = val2,
colLabels = val1,
rowColours = ["palegreen"] * 35,
colColours = ["palegreen"] * 24,
cellColours = [["grey"] * 24] * 35,
cellLoc ='center',
loc ='upper left')
ax.set_title('DATA TABLE', fontweight ="bold")
plt.show()
def main():
tab = cration_tableau()
if __name__ == '__main__':
main()
The problem is that the number of rows stops at the index of 24, when in fact I have 35 rows with values in the val2
list. The table doesn't show all the rows that are expected.
Is there a way to make the table take in consideration all the rows ?
Here is a screenshot of the output :