File mart.py changed (mode: 100644) (index 3110b2f..2fae30c) |
... |
... |
def plot_boundaries(ax, fmt='-b', nrod=200, **kwargs): |
91 |
91 |
return lines |
return lines |
92 |
92 |
|
|
93 |
93 |
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
|
def convex_plot(ax, fmt='-m', ns=100, **kwargs): |
|
97 |
|
if ax.sample_box.nvar == 2: |
|
98 |
|
simplices = ax.sample_box.convex_hull.simplices |
|
99 |
|
# convex hull should be made in the same space as triangulation, |
|
100 |
|
# Will we take coordinates in the triangulation space, I guess? |
|
101 |
|
sampled_plan_tri = getattr(ax.sample_box, ax.sample_box.tri_space) |
|
102 |
|
|
|
103 |
|
# hmm... |
|
104 |
|
lines = [] |
|
105 |
|
if ax.space == ax.sample_box.tri_space: |
|
106 |
|
for simplex in simplices: |
|
107 |
|
xy = sampled_plan_tri[simplex] |
|
108 |
|
x, y = xy.T |
|
109 |
|
lines.append(ax.plot(x, y, fmt, **kwargs)) |
|
110 |
|
|
|
111 |
|
else: |
|
112 |
|
#оӵ кулэ ӧвӧл обновлять экран карыны |
|
113 |
|
for simplex in simplices: |
|
114 |
|
start_id, end_id = simplex |
|
115 |
|
|
|
116 |
|
x_bound = np.linspace(sampled_plan_tri[start_id,0], sampled_plan_tri[end_id,0], ns, endpoint=True) |
|
117 |
|
y_bound = np.linspace(sampled_plan_tri[start_id,1], sampled_plan_tri[end_id,1], ns, endpoint=True) |
|
118 |
|
|
|
119 |
|
# sample compatible |
|
120 |
|
#оӵ малы транспонировать кароно? Озьы кулэ! |
|
121 |
|
bound_tri = np.vstack((x_bound, y_bound)).T |
|
122 |
|
#č vytvořme sample |
|
123 |
|
bound = ax.sample_box.f_model.new_sample(bound_tri, space=ax.sample_box.tri_space) |
|
124 |
|
|
|
125 |
|
xy = getattr(bound, ax.space) |
|
126 |
|
x, y = xy.T |
|
127 |
|
lines.append(ax.plot(x, y, fmt, **kwargs)) |
|
128 |
|
|
|
129 |
|
|
|
130 |
|
return lines |
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
94 |
134 |
def isočáry(ax, space, ngrid=200, limits=None): |
def isočáry(ax, space, ngrid=200, limits=None): |
95 |
135 |
if limits is None: |
if limits is None: |
96 |
136 |
xmin, xmax = ax.get_xlim() |
xmin, xmax = ax.get_xlim() |
|
... |
... |
def isočáry(ax, space, ngrid=200, limits=None): |
110 |
150 |
levels = misc.isolevels_2d(Z, const, np.flip(r_levels), from_top=False) |
levels = misc.isolevels_2d(Z, const, np.flip(r_levels), from_top=False) |
111 |
151 |
|
|
112 |
152 |
return ax.contour(X, Y, Z.reshape(ngrid, ngrid), levels, linewidths=lw, colors=[[96/255, 64/255, 96/255], [0.5, 0.25, 0.5], [161/255, 72/255, 162/255]])#, alpha=0.5) colors: h=300, s=50% |
return ax.contour(X, Y, Z.reshape(ngrid, ngrid), levels, linewidths=lw, colors=[[96/255, 64/255, 96/255], [0.5, 0.25, 0.5], [161/255, 72/255, 162/255]])#, alpha=0.5) colors: h=300, s=50% |
|
153 |
|
|
|
154 |
|
|
|
155 |
|
|
|
156 |
|
|
|
157 |
|
def center_spines(ax): |
|
158 |
|
# Move the left and bottom spines to x = 0 and y = 0, respectively. |
|
159 |
|
ax.spines["left"].set_position(("data", 0)) |
|
160 |
|
ax.spines["bottom"].set_position(("data", 0)) |
|
161 |
|
|
|
162 |
|
# Show the left and bottom spines |
|
163 |
|
ax.spines["left"].set_visible(True) |
|
164 |
|
ax.spines["bottom"].set_visible(True) |
|
165 |
|
|
|
166 |
|
# Hide the top and right spines. |
|
167 |
|
ax.spines["top"].set_visible(False) |
|
168 |
|
ax.spines["right"].set_visible(False) |
|
169 |
|
|
|
170 |
|
# Draw arrows (as black triangles: ">k"/"^k") at the end of the axes. In each |
|
171 |
|
# case, one of the coordinates (0) is a data coordinate (i.e., y = 0 or x = 0, |
|
172 |
|
# respectively) and the other one (1) is an axes coordinate (i.e., at the very |
|
173 |
|
# right/top of the axes). Also, disable clipping (clip_on=False) as the marker |
|
174 |
|
# actually spills out of the axes. |
|
175 |
|
ax.plot(1, 0, ">k", transform=ax.get_yaxis_transform(), clip_on=False) |
|
176 |
|
ax.plot(0, 1, "^k", transform=ax.get_xaxis_transform(), clip_on=False) |
|
177 |
|
|
|
178 |
|
|
|
179 |
|
def fix_locator(ax, loc): |
|
180 |
|
loc_x = mpl.ticker.FixedLocator(loc) |
|
181 |
|
ax.xaxis.set_major_locator(loc_x) |
|
182 |
|
loc_y = mpl.ticker.FixedLocator(loc) |
|
183 |
|
ax.yaxis.set_major_locator(loc_y) |
File mart3d.py changed (mode: 100644) (index 538b059..04326fe) |
... |
... |
import numpy as np |
9 |
9 |
from matplotlib import colors |
from matplotlib import colors |
10 |
10 |
import matplotlib.tri as mtri |
import matplotlib.tri as mtri |
11 |
11 |
|
|
|
12 |
|
from .simplex import is_outside |
|
13 |
|
|
12 |
14 |
# copied from simplex module |
# copied from simplex module |
13 |
15 |
# just don't want every time import simplex and its dependencies |
# just don't want every time import simplex and its dependencies |
14 |
16 |
def get_events(sx, simplices=None): |
def get_events(sx, simplices=None): |
|
... |
... |
def scatter_points(ax3d, zs=None, **kwargs): |
62 |
64 |
sample = getattr(ax3d.sample_box, ax3d.space) |
sample = getattr(ax3d.sample_box, ax3d.space) |
63 |
65 |
nsim = len(sample) |
nsim = len(sample) |
64 |
66 |
if zs is not None: |
if zs is not None: |
65 |
|
x, y = sample[:,:2].T |
|
|
67 |
|
x, y = sample[:,:2].T |
66 |
68 |
elif ax3d.sample_box.nvar == 2: |
elif ax3d.sample_box.nvar == 2: |
67 |
69 |
x, y = sample[:,:2].T |
x, y = sample[:,:2].T |
68 |
70 |
#zs = ax3d.sample_box.pdf(ax3d.space) |
#zs = ax3d.sample_box.pdf(ax3d.space) |
|
... |
... |
def density_surface(ax3d, **kwargs): |
151 |
153 |
|
|
152 |
154 |
return ax3d.plot_surface(X, Y, Z, **kwargs) |
return ax3d.plot_surface(X, Y, Z, **kwargs) |
153 |
155 |
|
|
|
156 |
|
|
|
157 |
|
def density_colored_surface(ax3d, colors=('#7735C2', '#808080'), **kwargs): |
|
158 |
|
xmin, xmax = ax3d.get_xlim() |
|
159 |
|
ymin, ymax = ax3d.get_ylim() |
|
160 |
|
|
|
161 |
|
inside_color, outside_color = colors |
154 |
162 |
|
|
|
163 |
|
if 'rcount' in kwargs: |
|
164 |
|
ngrid = kwargs['rcount'] |
|
165 |
|
else: |
|
166 |
|
ngrid = 50 |
|
167 |
|
|
|
168 |
|
x = np.linspace(xmin, xmax, ngrid) |
|
169 |
|
y = np.linspace(ymin, ymax, ngrid) |
|
170 |
|
X, Y = np.meshgrid(x, y) |
|
171 |
|
XY = np.vstack((X.flatten(), Y.flatten())).T |
|
172 |
|
z = ax3d.sample_box.sample_pdf(XY, ax3d.space) |
|
173 |
|
Z = z.reshape(ngrid, ngrid) |
|
174 |
|
|
|
175 |
|
# for facecolors |
|
176 |
|
_x = np.linspace(xmin, xmax, ngrid-1, endpoint=False) + (xmax-xmin)/(ngrid-1)/2 |
|
177 |
|
_y = np.linspace(ymin, ymax, ngrid-1, endpoint=False) + (ymax-ymin)/(ngrid-1)/2 |
|
178 |
|
_X, _Y = np.meshgrid(_x, _y) |
|
179 |
|
_XY = np.vstack((_X.flatten(), _Y.flatten())).T |
|
180 |
|
facecolors = np.full(len(_XY), inside_color) |
|
181 |
|
mask = is_outside(ax3d.sample_box.convex_hull, _XY) |
|
182 |
|
facecolors[mask] = outside_color |
|
183 |
|
facecolors = facecolors.reshape(ngrid-1, ngrid-1) |
|
184 |
|
|
|
185 |
|
return ax3d.plot_surface(X, Y, Z, facecolors = facecolors, **kwargs) |
155 |
186 |
|
|
156 |
187 |
|
|
157 |
188 |
def tri_surface(ax3d, **kwargs): |
def tri_surface(ax3d, **kwargs): |
|
... |
... |
def tri_colored_surfaces(ax3d, **kwargs): |
202 |
233 |
if np.any(events==2): |
if np.any(events==2): |
203 |
234 |
surf.append(ax3d.plot_trisurf(x, y, triangles[events==2], z, color=tri_colors[2], **kwargs)) |
surf.append(ax3d.plot_trisurf(x, y, triangles[events==2], z, color=tri_colors[2], **kwargs)) |
204 |
235 |
return surf |
return surf |
|
236 |
|
|
|
237 |
|
|
|
238 |
|
|
|
239 |
|
def wall(ax3d, lines2d, zmin=0, zmax=1, **kwargs): |
|
240 |
|
surf = list() |
|
241 |
|
for line2d in lines2d: |
|
242 |
|
x = line2d.get_xdata() |
|
243 |
|
y = line2d.get_ydata() |
|
244 |
|
_x = np.concatenate((x, x)) |
|
245 |
|
_y = np.concatenate((y, y)) |
|
246 |
|
_z = np.concatenate([np.full(len(x), zmin), np.full(len(x), zmax)]) |
|
247 |
|
tri = mtri.Triangulation(_x, _z) |
|
248 |
|
triangles = tri.get_masked_triangles() |
|
249 |
|
surf.append(ax3d.plot_trisurf(_x, _y, _z, triangles=triangles, **kwargs)) |
|
250 |
|
|
|
251 |
|
|