import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.mplot3d import Axes3D import random def descartes_3d(ax, ran_x, ran_y, ran_z, ax_title, x_label = "s", y_label = "t", z_label="r2"): ax.set_xlabel(x_label, fontsize = 12) ax.set_ylabel(y_label, fontsize = 12) ax.set_zlabel(z_label, fontsize = 12) ax.set_xlim(ran_x[0], ran_x[1]) ax.set_ylim(ran_y[0], ran_y[1]) ax.set_zlim(ran_z[0], ran_z[1]) ax.set_title(ax_title, fontsize = 16) ax.grid() fig = plt.figure(figsize = (7, 7)) ax = fig.add_subplot(111, projection='3d') title1 = "Touhoku University 2023 Math qu.4 NO2" descartes_3d(ax, [-0.1, 1.1], [-0.1, 1.1], [2, 5], title1) r2_s = [] for s in np.linspace(0,1,80): for t in np.linspace(0,1,80): if s+t <= 1: r2=8/3*s**2+3*t**2+16/3*s*t-3*t-4*s+17/4 r2_s.append(r2) r=random.random() g=random.random() b=random.random() ax.scatter(s,t,r2,s=1,color=(r, g, b)) ax.text(0.2,-0.6,8,"The maximum of the radius is {}".format(max(r2_s)),color="blue",size=14) ax.text(0.2,-0.6,7.7,"The minimum of the radius is {}".format(min(r2_s)),color="blue",size=14) plt.show()