May 2017
Intermediate to advanced
310 pages
8h 5m
English
In trying to visualize data, stacking a number of bars enables one to further understand how one piece of data or variable varies with another:
data = [ [8., 57., 22., 10.], [16., 7., 32., 40.], ] import numpy as np x_values = np.arange(4) plt.bar(x_values + 0.00, data[0], color='r', width=0.30) plt.bar(x_values + 0.30, data[1], color='y', width=0.30) plt.show()
The y values for the first batch of data are [8., 57., 22., 10.]. The second batch is [16., 7., 32., 40.]. When the bars are plotted, 8 and 16 will occupy the same x position, side by side.
x_values = np.arange(4) generates the array with values [0, 1, 2, 3]. The first set of bars are drawn first at position x_values + 0.30. Thus, the first x values will ...