Customizing the appearance of plots

To change the appearance of the preceding table so that Nitrogen is blue, Oxygen is green, and Argon is red, we will pass some arguments in the following code:

# Cell colours w/ rowColours, cellColours & colColours
fracs = (78, 21, 1)
labels = ('Nitrogen', 'Oxygen', 'Argon')
plt.pie(fracs, labels=labels)
plt.table(cellText=[fracs], rowLabels=['Fraction'], colLabels=labels, colColours=['b','g','r'])
plt.gca().set_aspect('equal')

The column labels will change. The output is as follows:

To change the color of the Fraction row, change callColors to cellColors. Since it has to match the same dimensions, we can give the same dimensions a three by one matrix. By doing this, we get colored cells:

# Cell colours w/ rowColours, cellColours & colColours
fracs = (78, 21, 1)
labels = ('Nitrogen', 'Oxygen', 'Argon')
plt.pie(fracs, labels=labels)
plt.table(cellText=[fracs], rowLabels=['Fraction'], colLabels=labels, cellColours=[['b','g','r']])
plt.gca().set_aspect('equal')

The output for the preceding code is as follows:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset