[1]:
import ograph.ofig as ofig
import ograph.oplot as oplot
import ograph.oconfig as oconfig
import matplotlib.pyplot as plt
import numpy as np
Plotting in 3 Dimensions
OPlot is built upon a set of 3D plotting utilities. These utilities have been continuously enhanced and polish across versions.
Several utilities in ograph.ofig can create and check figures. To initialise a figure in 3D, let’s call .fig3 to create it!
[2]:
ofig.fig3(xlim=(0, 10),
ylim=(-10, 3),
zlim=(0, 1))
ofig.annotate("Title", "x", "y", "z")
plt.show()
Use plot_wireframe for wireframe plots, and plot_surface for surface plots.
[3]:
def himmelblau(x, y):
return (x ** 2 + y - 11) ** 2 + (x + y ** 2 - 7) ** 2
ofig.fig3()
oplot.surface(himmelblau, (-5,5), (-5,5), alpha=0.5)
plt.show()
[4]:
def himmelblau(x, y):
return (x ** 2 + y - 11) ** 2 + (x + y ** 2 - 7) ** 2
ofig.fig3()
oplot.wireframe(himmelblau, (-5,5), (-5,5), alpha=0.5)
plt.show()
[5]:
ofig.fig3()
oplot.contour(himmelblau, (-5,5), (-5,5), levels=100, alpha=0.5)
plt.show()
[6]:
import ograph.ofunc as ofunc
from scipy.spatial import ConvexHull, distance #type: ignore
fig = plt.figure()
ax = plt.axes()
oplot.chull(ofunc.unit_square)
[7]:
fig = plt.figure()
ax = plt.axes(projection="3d")
oplot.chull(ofunc.unit_cube)
[ ]:
transform = np.array([
[2,0,0],
[0,1,0],
[0,3,1]
])
source = ofunc.unit_cube.T
new_unit = transform.dot(source).T
# np.matmul(transform, source)
fig = plt.figure()
ax = plt.axes(projection="3d")
ax.view_init(10, 120)
ax.set_zlabel("z", fontname = 'PT Serif')
ofig.annotate("", "x", "y", "z")
ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])
ax.set_xlim3d(-0.5, 1.5)
ax.set_zlim3d(0, 1.5)
for side in ['top','right','bottom','left']:
ax.spines[side].set_visible(False)
ax.tick_params(axis='both',which='both',labelbottom=False,bottom=False,left=False)
oplot.chull(ofunc.unit_cube)
oplot.chull(new_unit)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[8], line 15
13 ax.view_init(10, 120)
14 ax.set_zlabel("z", fontname = 'PT Serif')
---> 15 oplot.annotate("", "x", "y", "z")
16 ax.set_xticks([])
17 ax.set_yticks([])
AttributeError: module 'ograph.oplot' has no attribute 'annotate'
Plot an arrow with oplot.arrow.
[ ]:
ofig.fig3()
oplot.arrow((0,0,0),
(1,1,1))
plt.show()
[ ]:
from ograph.ofunc import himmelblau
ofig.fig2()
oplot.contour(himmelblau, (-6, 6), (-6, 6), cmap="Spectral", colorbar=False)
plt.show()
[ ]:
ofig.fig3()
oplot.surface(himmelblau, (-5, 5), (-5, 5), cmap="Spectral", colorbar=False)
plt.show()