# imports: numpy(optional if you want to use the NumPy arrays.) import numpy as np # imports: matplotlib.pyplot for plotting points import matplotlib.pyplot as plt # imports: mplot3d from mpl_toolkits for 3D graph from mpl_toolkits import mplot3d # invoke plot figure fig = plt.figure() # invoke 3D subplot ax1 = fig.add_subplot(projection="3d") # set measures for the x-coordinates ax1.set_xticks(range(0,9,1)) # set measures for the y-coordinates ax1.set_yticks(range(0,55,1)) # setting as labeled: colummn, row, values ax1.set_ylabel('column') ax1.set_xlabel('row') ax1.set_zlabel('values') # points to plot. changed from 10 separate lists to a # dictionary/hash-map of numbered keys with tuples for values. points = { 0 : (22, 22, 0, 28, 0, 24, 12, 0, 12, 0), 1 : (0, 28, 5, 7, 13, 23, 23, 4, 6, 5), 2 : (13, 0, 13, 0, 0, 0, 16, 0, 11, 0), 3 : (11, 3, 8, 10, 25, 25, 0, 17, 0, 9), 4 : (10, 7, 9, 6, 6, 12, 18, 3, 0, 17), 5 : (0, 17, 12, 12, 13, 13, 0, 8, 10, 0), 6 : (45, 0, 51, 0, 0, 29, 0, 0, 45, 0), 7 : (4, 0, 0, 0, 5, 0, 9, 0, 8, 0), 8 : (9, 19, 12, 5, 0, 9, 6, 0, 0, 0), 9 : (24, 28, 28, 24, 12, 0, 29, 0, 0), } # for loop which increments the y-axis measurement, along with x # z-values come from the tuples. # define a function to plot the scatterplot. def plotit(choice): ax1.scatter(x, y, z, marker='o', color=choice) for x, v in points.items(): y = 0 for z in v: if x == 0 and y <= 1 and z == 22: plotit('violet') if x == 0 and y > 1 and z > 0: plotit('red') elif x == 9 and y == 7 and z == 29: plotit('violet') elif x == 1 and z >= 1: plotit('red') elif x == 2 and y == 0: plotit('red') elif x == 2 and y > 0 and z > 0: plotit('orange') elif x == 3 and z >= 1: plotit('orange') elif x == 4 and z >= 1: plotit('orange') elif x == 5 and y <= 7: plotit('yellow') elif x == 5 and y == 8: plotit('orange') elif x == 6 and y == 0: plotit('orange') elif x == 6 and y > 1 and z > 0: plotit('blue') elif x == 7 and z > 0: plotit('green') elif x == 8 and z > 0: plotit('green') elif x == 9 and y == 2: plotit('green') elif x == 9 and y < 5 and z < 28: plotit('blue') elif x == 9 and y == 1: plotit('blue') elif x == 9 and y == 7: plotit('violet') y += 1 # show 3D graph plt.show()