Created
October 2, 2020 12:56
-
-
Save sabopy/d1c2e31f90414c0fb63ae087fed754e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%matplotlib widget | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib.ticker as ticker | |
plt.rcParams['font.size']=20 | |
#data | |
x = np.linspace(1,9,9)[:,np.newaxis] | |
y = np.linspace(1,9,9)[:,np.newaxis].T | |
kuku = x*y | |
kuku = kuku.flatten().astype(int) | |
#mouse event | |
def enter_axes(event): | |
print('enter_axes', event.inaxes) | |
event.inaxes.patch.set_facecolor('w') | |
event.canvas.draw() | |
def leave_axes(event): | |
print('leave_axes', event.inaxes) | |
event.inaxes.patch.set_facecolor('k') | |
event.canvas.draw() | |
#make table | |
fig,ax = plt.subplots(ncols=9,nrows=9,figsize=(8,8)) | |
fig.suptitle('Multiplication table') | |
ax = ax.ravel() | |
[ax[i].set_facecolor('k') for i in range(len(ax))] | |
[ax[i].xaxis.set_major_locator(ticker.NullLocator()) for i in range(len(ax))] | |
[ax[i].yaxis.set_major_locator(ticker.NullLocator()) for i in range(len(ax))] | |
[ax[i].text(0.5, 0.5, str(kuku[i]), ha='center',va='center', transform=ax[i].transAxes) for i in range(len(ax))] | |
[ax[i].set_ylabel(str(kuku[i]),rotation=0,y=0.2,labelpad=10) for i in range(0,81,9)] | |
[ax[i].set_title(str(kuku[i])) for i in range(0,9,1)] | |
fig.canvas.mpl_connect('axes_enter_event', enter_axes) | |
fig.canvas.mpl_connect('axes_leave_event', leave_axes) | |
plt.show() | |
#version | |
print(np.__version__) | |
1.19.1 | |
import matplotlib | |
print(matplotlib.__version__) | |
3.3.2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment