
上QQ阅读APP看书,第一时间看更新
How it works...
Here is the explanation for the code:
- pd.read_excel() reads the Excel file into a pandas DataFrame.
- np.asarray() converts a DataFrame into a NumPy array, as required for further processing. It is a 20 x 7 matrix.
- np.abs() returns absolute values of the matrix that is given as input.
- np.abs(matrix).max() returns the maximum value from an absolute matrix.
- np.log() returns a natural logarithmic value of the argument that is passed.
- np.ceil() rounds up the argument to the next highest value for a given floating point number, for example np.ceil(2.2) = 3.0.
- ax.patch.set_facecolor('gray') sets the color of each of the box points to gray.
- ax.set_aspect('equal', 'box') specifies the aspect ratio (the ratio of width to height) and shape of the points on the graph to be a box.
- ax.xaxis.set_major_locator(plt.NullLocator()) sets the x axis ticks to nulls so that there are no ticks marked, and no ticklabels placed.
- Initiate a for loop to go over each of the elements of the weight matrix, and set the color to white for positive values, black for negative values, and size proportional to max_weight. Finally, ax.autoscale_view() arranges all the boxes neatly and plots the Hinton diagram.
You should get the output as follows: