# 3Dimension Plotting in Python

### Series: Python for kids

In our endavor to make learning fun and free of memorization, we have been using Python to allow children to experiment and analyze data to form their own opinion and discover facts. This way, children engage is learning process with more intensity and the they show higher retention rate vis a vis conventional learning.

This makes them think and try different things before they get it right. The focus shifts from being always ‘right’ to get it right after several failed attempts. In this part of the series

Children create simple shapes using markers, move marker left, right, front, back, up and down. They learn coordinates geometry where the position of points on the 3D plane.

In this blog we are using Matplotlibn library. Matplotlib is a plotting library for the Python programming language and its numerical mathematics extension NumPy.

### The Matplotlib Jupyter Widget Backend

ipympl enables the interactive features of matplotlib in the Jupyter notebook and in JupyterLab. To enable the ipympl backend, simply use the matplotlib Jupyter magic: # %matplotlib widget

In [1]:
import matplotlib.pyplot as plt
import numpy as np
# %matplotlib widget


## Plot a point at origin(0, 0, 0) in 3D

In [2]:
fig = plt.figure(figsize = (5, 5))
ax = plt.axes(projection='3d')

ax.plot(0, 0, 0, color = 'red', marker = '*')

plt.show()

C:\Users\Nutan\AppData\Local\Temp\ipykernel_1144\2866066107.py:2: MatplotlibDeprecationWarning: Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments. The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot().
ax = plt.axes(projection='3d')

Figure

### Change color of point

In [3]:
fig = plt.figure(figsize = (5, 5))
ax = plt.axes(projection='3d')

ax.plot(0, 0, 0, color = 'green', marker = 'o')

plt.show()

C:\Users\Nutan\AppData\Local\Temp\ipykernel_1144\1351514269.py:2: MatplotlibDeprecationWarning: Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments. The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot().
ax = plt.axes(projection='3d')

Figure

### Make it bigger point

In [4]:
fig = plt.figure(figsize = (5, 5))
ax = plt.axes(projection='3d')

ax.plot(0, 0, 0, color = 'red',
marker = 'o', markersize = 20)

plt.show()

C:\Users\Nutan\AppData\Local\Temp\ipykernel_1144\1314132036.py:2: MatplotlibDeprecationWarning: Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments. The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot().
ax = plt.axes(projection='3d')

Figure

### Create different shape like triangle in place of point

In [5]:
fig = plt.figure(figsize = (5, 5))
ax = plt.axes(projection='3d')

ax.plot(0, 0, 0, color = 'red', marker = '^', markersize = 20)

plt.show()

C:\Users\Nutan\AppData\Local\Temp\ipykernel_1144\2692021183.py:2: MatplotlibDeprecationWarning: Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments. The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot().
ax = plt.axes(projection='3d')

Figure

## Create points left, right, front, back, up and down from the origin

### Left and right points

In [6]:
fig = plt.figure(figsize = (5, 5))
ax = plt.axes(projection='3d')

ax.plot(0, 0, 0, color = 'red', marker = '^', markersize = 10)
ax.plot(1, 0, 0, color = 'green', marker = 'o', markersize = 10)
ax.plot(-1, 0, 0, color = 'blue', marker = 'o', markersize = 10)

plt.show()

C:\Users\Nutan\AppData\Local\Temp\ipykernel_1144\2614721598.py:2: MatplotlibDeprecationWarning: Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments. The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot().
ax = plt.axes(projection='3d')

Figure

### Front and back points

In [7]:
fig = plt.figure(figsize = (5, 5))
ax = plt.axes(projection='3d')

ax.plot(0, 0, 0, color = 'red', marker = '^', markersize = 10)

ax.plot(1, 0, 0, color = 'green', marker = 'o', markersize = 10)
ax.plot(-1, 0, 0, color = 'blue', marker = 'o', markersize = 10)

ax.plot(0, 1, 0, color = 'yellow', marker = 'o', markersize = 10)
ax.plot(0, -1, 0, color = 'purple', marker = 'o', markersize = 10)

plt.show()

C:\Users\Nutan\AppData\Local\Temp\ipykernel_1144\2987012512.py:2: MatplotlibDeprecationWarning: Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments. The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot().
ax = plt.axes(projection='3d')

Figure

### Up and down points

In [8]:
fig = plt.figure(figsize = (5, 5))
ax = plt.axes(projection='3d')

ax.plot(0, 0, 0, color = 'red', marker = '^', markersize = 10)

ax.plot(1, 0, 0, color = 'green', marker = 'o', markersize = 10)
ax.plot(-1, 0, 0, color = 'blue', marker = 'o', markersize = 10)

ax.plot(0, 1, 0, color = 'yellow', marker = 'o', markersize = 10)
ax.plot(0, -1, 0, color = 'purple', marker = 'o', markersize = 10)

ax.plot(0, 0, 1, color = 'cyan', marker = 'o', markersize = 10)
ax.plot(0, 0, -1, color = 'black', marker = 'o', markersize = 10)

plt.show()

C:\Users\Nutan\AppData\Local\Temp\ipykernel_1144\3695728694.py:2: MatplotlibDeprecationWarning: Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments. The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot().
ax = plt.axes(projection='3d')

Figure

In [9]:
fig = plt.figure(figsize = (5, 5))
ax = plt.axes(projection='3d')

ax.plot(0, 0, 0, color = 'red', marker = '^', markersize = 10)
ax.text(0 + 0.03, 0 + 0.01, 0 + 0.01, s = 'O', fontsize = 10)

ax.plot(1, 0, 0, color = 'green', marker = 'o', markersize = 10)
ax.plot(-1, 0, 0, color = 'blue', marker = 'o', markersize = 10)

ax.plot(0, 1, 0, color = 'yellow', marker = 'o', markersize = 10)
ax.plot(0, -1, 0, color = 'purple', marker = 'o', markersize = 10)

ax.plot(0, 0, 1, color = 'cyan', marker = 'o', markersize = 10)
ax.plot(0, 0, -1, color = 'black', marker = 'o', markersize = 10)

plt.show()

C:\Users\Nutan\AppData\Local\Temp\ipykernel_1144\3042329124.py:2: MatplotlibDeprecationWarning: Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments. The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot().
ax = plt.axes(projection='3d')

Figure

## Connect left and right point

In [10]:
fig = plt.figure(figsize = (5, 5))
ax = plt.axes(projection='3d')

ax.plot(0, 0, 0, color = 'red', marker = '^', markersize = 10)
ax.text(0 + 0.03, 0 + 0.01, 0 + 0.01, s = 'O', fontsize = 10)

ax.plot(1, 0, 0, color = 'green', marker = 'o', markersize = 10)
ax.plot(-1, 0, 0, color = 'blue', marker = 'o', markersize = 10)

ax.plot(
[1, -1],
[0, 0],
[0, 0]
)

ax.plot(0, 1, 0, color = 'yellow', marker = 'o', markersize = 10)
ax.plot(0, -1, 0, color = 'purple', marker = 'o', markersize = 10)

ax.plot(0, 0, 1, color = 'cyan', marker = 'o', markersize = 10)
ax.plot(0, 0, -1, color = 'black', marker = 'o', markersize = 10)

plt.show()

C:\Users\Nutan\AppData\Local\Temp\ipykernel_1144\3211651894.py:2: MatplotlibDeprecationWarning: Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments. The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot().
ax = plt.axes(projection='3d')

Figure

## Connect front and back point

In [11]:
fig = plt.figure(figsize = (5, 5))
ax = plt.axes(projection='3d')

ax.plot(0, 0, 0, color = 'red', marker = '^', markersize = 10)
ax.text(0 + 0.03, 0 + 0.01, 0 + 0.01, s = 'O', fontsize = 10)

ax.plot(1, 0, 0, color = 'green', marker = 'o', markersize = 10)
ax.plot(-1, 0, 0, color = 'blue', marker = 'o', markersize = 10)

ax.plot(
[1, -1],
[0, 0],
[0, 0]
)

ax.plot(0, 1, 0, color = 'yellow', marker = 'o', markersize = 10)
ax.plot(0, -1, 0, color = 'purple', marker = 'o', markersize = 10)

ax.plot(
[0, 0],
[1, -1],
[0, 0]
)

ax.plot(0, 0, 1, color = 'cyan', marker = 'o', markersize = 10)
ax.plot(0, 0, -1, color = 'black', marker = 'o', markersize = 10)

plt.show()

C:\Users\Nutan\AppData\Local\Temp\ipykernel_1144\1746733648.py:2: MatplotlibDeprecationWarning: Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments. The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot().
ax = plt.axes(projection='3d')

Figure

## Connect up and down point

In [12]:
fig = plt.figure(figsize = (5, 5))
ax = plt.axes(projection='3d')

ax.plot(0, 0, 0, color = 'red', marker = '^', markersize = 10)
ax.text(0 + 0.03, 0 + 0.01, 0 + 0.01, s = 'O', fontsize = 10)

ax.plot(1, 0, 0, color = 'green', marker = 'o', markersize = 10)
ax.plot(-1, 0, 0, color = 'blue', marker = 'o', markersize = 10)

ax.plot(
[1, -1],
[0, 0],
[0, 0]
)

ax.plot(0, 1, 0, color = 'yellow', marker = 'o', markersize = 10)
ax.plot(0, -1, 0, color = 'purple', marker = 'o', markersize = 10)

ax.plot(
[0, 0],
[1, -1],
[0, 0]
)

ax.plot(0, 0, 1, color = 'cyan', marker = 'o', markersize = 10)
ax.plot(0, 0, -1, color = 'black', marker = 'o', markersize = 10)

ax.plot(
[0, 0],
[0, 0],
[1, -1]
)

plt.show()

C:\Users\Nutan\AppData\Local\Temp\ipykernel_1144\838292702.py:2: MatplotlibDeprecationWarning: Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments. The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot().
ax = plt.axes(projection='3d')

Figure