import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as tck
import matplotlib.patches as pat
import matplotlib.path as pth
import matplotlib.patheffects as pff
import matplotlib.lines as lns
import matplotlib.transforms as tra
import mpl_toolkits.mplot3d
import matplotlib.tri as plt_tri
from mpl_toolkits.axes_grid1 import make_axes_locatable
NaN = np.nan
EXTRA_ARTISTS = []
def add_to_ea(obj):
global EXTRA_ARTISTS
if obj!=None: EXTRA_ARTISTS.append(obj)
THREE_D = dict()
THREE_D_ACTIVE = (1,1,1)
def ax3d():
global THREE_D
global THREE_D_ACTIVE
if not THREE_D_ACTIVE in THREE_D:
a, b, c = THREE_D_ACTIVE
THREE_D[THREE_D_ACTIVE] = plt.gcf().add_subplot(a,b,c,projection='3d')
THREE_D[THREE_D_ACTIVE].set_xlabel('x')
THREE_D[THREE_D_ACTIVE].set_ylabel('y')
THREE_D[THREE_D_ACTIVE].set_zlabel('z')
add_to_ea(THREE_D[THREE_D_ACTIVE])
return THREE_D[THREE_D_ACTIVE]
def subplot_3d(a,b,c):
global THREE_D_ACTIVE
THREE_D_ACTIVE = (a,b,c)
ax3d()
def data_to_axis(coords):
plt.axis() return plt.gca().transLimits.transform(coords)
def axis_to_data(coords):
plt.axis() return plt.gca().transLimits.inverted().transform(coords)
def set_equal_axes():
global THREE_D
if len(THREE_D) == 0:
ax = plt.gca()
ax.axes.set_aspect('equal')
return
try:
ax = ax3d()
ax.set_box_aspect([1,1,1])
limits = np.array([ax.get_xlim3d(), ax.get_ylim3d(), ax.get_zlim3d()])
origin = np.mean(limits, axis=1)
radius = 0.5 * np.max(np.abs(limits[:, 1] - limits[:, 0]))
x, y, z = origin
ax.set_xlim3d([x - radius, x + radius])
ax.set_ylim3d([y - radius, y + radius])
ax.set_zlim3d([z - radius, z + radius])
except:
import matplotlib
print('VERSION of MATPLOTLIB = {}'.format(matplotlib.__version__))
print('ERROR: set_box_aspect is missing in this version of Matplotlib')
def ignore_this(*args, **kwargs):
pass
xy=np.array([[0,0],[1,0],])
plt.plot(xy[:,0],xy[:,1],label=r'x axis for "test"',color='red',linewidth=2)
plt.gca().set_axisbelow(True)
plt.grid(linestyle='--',color='grey',zorder=-1000)
plt.gca().set_xlabel(r'x')
plt.gca().set_ylabel(r'y')
xy=np.array([[0,0],[0,1],])
plt.plot(xy[:,0],xy[:,1],label=r'y axis for "test"',color='red',linewidth=1)
plt.gca().set_axisbelow(True)
plt.grid(linestyle='--',color='grey',zorder=-1000)
plt.gca().set_xlabel(r'x')
plt.gca().set_ylabel(r'y')
h,l=plt.gca().get_legend_handles_labels()
if len(h)>0 and len(l)>0:
leg=plt.legend(handlelength=3,ncol=1,loc='best')
add_to_ea(leg)
xy=np.array([[-1.25,-1.25],[1.25,-1.25],[1.25,1.25],[-1.25,1.25],[-1.25,-1.25],])
plt.plot(xy[:,0],xy[:,1],label=r'Frame of ""',color='yellow',linestyle='solid',linewidth=1,markerfacecolor='yellow',markevery=1,markersize=10,marker='.')
xy=np.array([[0,0],[1,0],])
plt.plot(xy[:,0],xy[:,1],label=r'x axis for "test"',color='red',linewidth=2)
plt.gca().set_axisbelow(True)
plt.grid(linestyle='--',color='grey',zorder=-1000)
plt.gca().set_xlabel(r'x')
plt.gca().set_ylabel(r'y')
xy=np.array([[0,0],[0,1],])
plt.plot(xy[:,0],xy[:,1],label=r'y axis for "test"',color='red',linewidth=1)
plt.gca().set_axisbelow(True)
plt.grid(linestyle='--',color='grey',zorder=-1000)
plt.gca().set_xlabel(r'x')
plt.gca().set_ylabel(r'y')
h,l=plt.gca().get_legend_handles_labels()
if len(h)>0 and len(l)>0:
leg=plt.legend(handlelength=3,ncol=1,loc='best')
add_to_ea(leg)
xy=np.array([[-1.5,-1.5],[1.5,-1.5],[1.5,1.5],[-1.5,1.5],[-1.5,-1.5],])
plt.plot(xy[:,0],xy[:,1],label=r'Frame of ""',color='red',linestyle='solid',linewidth=1,markerfacecolor='red',markevery=1,markersize=10,marker='.')
xy=np.array([[0,0],[1,0],])
plt.plot(xy[:,0],xy[:,1],label=r'x axis for "test"',color='red',linewidth=2)
plt.gca().set_axisbelow(True)
plt.grid(linestyle='--',color='grey',zorder=-1000)
plt.gca().set_xlabel(r'x')
plt.gca().set_ylabel(r'y')
xy=np.array([[0,0],[0,1],])
plt.plot(xy[:,0],xy[:,1],label=r'y axis for "test"',color='red',linewidth=1)
plt.gca().set_axisbelow(True)
plt.grid(linestyle='--',color='grey',zorder=-1000)
plt.gca().set_xlabel(r'x')
plt.gca().set_ylabel(r'y')
h,l=plt.gca().get_legend_handles_labels()
if len(h)>0 and len(l)>0:
leg=plt.legend(handlelength=3,ncol=1,loc='best')
add_to_ea(leg)
xy=np.array([[-1,0],[0,0],[0,-1],[-1,-1],[-1,0],])
plt.plot(xy[:,0],xy[:,1],label=r'Frame',linestyle='solid',linewidth=1,markerfacecolor='purple',markevery=1,markersize=10,marker='.')
t=plt.text(-1,-1,r'0',color='purple',fontsize=5)
t=plt.text(0,-1,r'1',color='purple',fontsize=5)
t=plt.text(1,-1,r'2',color='purple',fontsize=5)
t=plt.text(-1,0,r'3',color='purple',fontsize=5)
t=plt.text(0,0,r'4',color='purple',fontsize=5)
t=plt.text(1,0,r'5',color='purple',fontsize=5)
t=plt.text(-1,1,r'6',color='purple',fontsize=5)
t=plt.text(0,1,r'7',color='purple',fontsize=5)
t=plt.text(1,1,r'8',color='purple',fontsize=5)
xy=np.array([[-1,-1],[0,-1],[1,-1],[-1,0],[0,0],[1,0],[-1,1],[0,1],[1,1],])
plt.plot(xy[:,0],xy[:,1],label=r'Grid points: ""',linestyle='none',markerfacecolor='blue',markevery=1,markersize=7,marker='.')
xy=np.array([[-0.9044611903823121,-0.6890808322504309],])
plt.plot(xy[:,0],xy[:,1],label=r'x, y residuals: 0.096, 0.311',linestyle='none',markerfacecolor='#eeea83',markevery=1,markersize=10,marker='*')
xy=np.array([[-1,-1],])
plt.plot(xy[:,0],xy[:,1],label=r'Corner: (-1.000,-1.000)',linestyle='none',markerfacecolor='#eeea83',markevery=1,markersize=10,marker='.')
plt.gcf().set_size_inches(10,10)
plt.gca().get_yaxis().set_major_locator(tck.MaxNLocator(4))
plt.gca().get_xaxis().set_major_locator(tck.MaxNLocator(4))
plt.gca().set_axisbelow(True)
plt.grid(linestyle='--',color='grey',zorder=-1000)
plt.gca().set_xlabel(r'x')
plt.gca().set_ylabel(r'y')
h,l=plt.gca().get_legend_handles_labels()
if len(h)>0 and len(l)>0:
leg=plt.legend(handlelength=3,ncol=1,loc='best')
add_to_ea(leg)
xy=np.array([[0,0],[1,0],])
plt.plot(xy[:,0],xy[:,1],label=r'x axis for "test"',color='red',linewidth=2)
plt.gca().set_axisbelow(True)
plt.grid(linestyle='--',color='grey',zorder=-1000)
plt.gca().set_xlabel(r'x')
plt.gca().set_ylabel(r'y')
xy=np.array([[0,0],[0,1],])
plt.plot(xy[:,0],xy[:,1],label=r'y axis for "test"',color='red',linewidth=1)
plt.gca().set_axisbelow(True)
plt.grid(linestyle='--',color='grey',zorder=-1000)
plt.gca().set_xlabel(r'x')
plt.gca().set_ylabel(r'y')
h,l=plt.gca().get_legend_handles_labels()
if len(h)>0 and len(l)>0:
leg=plt.legend(handlelength=3,ncol=1,loc='best')
add_to_ea(leg)
xy=np.array([[0,0.5],[0.5,0.5],[0.5,0],[0,0],[0,0.5],])
plt.plot(xy[:,0],xy[:,1],label=r'Frame',linestyle='solid',linewidth=1,markerfacecolor='purple',markevery=1,markersize=10,marker='.')
t=plt.text(-1,-1,r'0',color='purple',fontsize=5)
t=plt.text(-0.5,-1,r'1',color='purple',fontsize=5)
t=plt.text(0,-1,r'2',color='purple',fontsize=5)
t=plt.text(0.5,-1,r'3',color='purple',fontsize=5)
t=plt.text(1,-1,r'4',color='purple',fontsize=5)
t=plt.text(-1,-0.5,r'5',color='purple',fontsize=5)
t=plt.text(-0.5,-0.5,r'6',color='purple',fontsize=5)
t=plt.text(0,-0.5,r'7',color='purple',fontsize=5)
t=plt.text(0.5,-0.5,r'8',color='purple',fontsize=5)
t=plt.text(1,-0.5,r'9',color='purple',fontsize=5)
t=plt.text(-1,0,r'10',color='purple',fontsize=5)
t=plt.text(-0.5,0,r'11',color='purple',fontsize=5)
t=plt.text(0,0,r'12',color='purple',fontsize=5)
t=plt.text(0.5,0,r'13',color='purple',fontsize=5)
t=plt.text(1,0,r'14',color='purple',fontsize=5)
t=plt.text(-1,0.5,r'15',color='purple',fontsize=5)
t=plt.text(-0.5,0.5,r'16',color='purple',fontsize=5)
t=plt.text(0,0.5,r'17',color='purple',fontsize=5)
t=plt.text(0.5,0.5,r'18',color='purple',fontsize=5)
t=plt.text(1,0.5,r'19',color='purple',fontsize=5)
t=plt.text(-1,1,r'20',color='purple',fontsize=5)
t=plt.text(-0.5,1,r'21',color='purple',fontsize=5)
t=plt.text(0,1,r'22',color='purple',fontsize=5)
t=plt.text(0.5,1,r'23',color='purple',fontsize=5)
t=plt.text(1,1,r'24',color='purple',fontsize=5)
xy=np.array([[-1,-1],[-0.5,-1],[0,-1],[0.5,-1],[1,-1],[-1,-0.5],[-0.5,-0.5],[0,-0.5],[0.5,-0.5],[1,-0.5],[-1,0],[-0.5,0],[0,0],[0.5,0],[1,0],[-1,0.5],[-0.5,0.5],[0,0.5],[0.5,0.5],[1,0.5],[-1,1],[-0.5,1],[0,1],[0.5,1],[1,1],])
plt.plot(xy[:,0],xy[:,1],label=r'Grid points: ""',linestyle='none',markerfacecolor='blue',markevery=1,markersize=7,marker='.')
xy=np.array([[0.23491095388729488,0.432296952277462],])
plt.plot(xy[:,0],xy[:,1],label=r'x, y residuals: 0.235, -0.068',linestyle='none',markerfacecolor='#eeea83',markevery=1,markersize=10,marker='*')
xy=np.array([[-1,-1],])
plt.plot(xy[:,0],xy[:,1],label=r'Corner: (-1.000,-1.000)',linestyle='none',markerfacecolor='#eeea83',markevery=1,markersize=10,marker='.')
plt.gcf().set_size_inches(10,10)
plt.gca().get_yaxis().set_major_locator(tck.MaxNLocator(6))
plt.gca().get_xaxis().set_major_locator(tck.MaxNLocator(6))
plt.gca().set_axisbelow(True)
plt.grid(linestyle='--',color='grey',zorder=-1000)
plt.gca().set_xlabel(r'x')
plt.gca().set_ylabel(r'y')
h,l=plt.gca().get_legend_handles_labels()
if len(h)>0 and len(l)>0:
leg=plt.legend(handlelength=3,ncol=1,loc='best')
add_to_ea(leg)
fn=r'test'
plt.savefig(fn,bbox_inches='tight',bbox_extra_artists=EXTRA_ARTISTS)
plt.show()