-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
119 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from vedo import * | ||
import matplotlib.colors as colors | ||
import matplotlib.pyplot as plt | ||
|
||
settings.default_font = "Antares" | ||
|
||
man = Mesh(dataurl + "man.vtk") | ||
h_knees = -0.5 | ||
over_limit = 1.5 | ||
under_limit = -1.4 | ||
|
||
# let the scalar be the z coordinate of the mesh vertices | ||
scals = man.vertices[:, 2] | ||
|
||
# build a complicated colour map | ||
c1 = plt.cm.viridis(np.linspace(0.0, 0.7, 128)) | ||
c2 = plt.cm.terrain(np.linspace(0.5, 0.8, 128)) | ||
c = np.vstack((c1, c2)) | ||
cmap = colors.LinearSegmentedColormap.from_list("heights", c) | ||
cmap.set_over(color="red") | ||
cmap.set_under(color="orange") | ||
norm = colors.TwoSlopeNorm(h_knees, vmin=under_limit, vmax=over_limit) | ||
mapper = plt.cm.ScalarMappable(norm=norm, cmap=cmap) | ||
|
||
# build look up table | ||
lut = build_lut( | ||
[(v, mapper.to_rgba(v)[:3]) for v in np.linspace(under_limit, over_limit, 128)], | ||
above_color=cmap.get_over()[:3], | ||
below_color=cmap.get_under()[:3], | ||
vmin=under_limit, | ||
vmax=over_limit, | ||
) | ||
|
||
man.cmap(lut, scals) | ||
man.add_scalarbar3d(above_text="Above Eyes", below_text="Below Heels") | ||
man.scalarbar = man.scalarbar.clone2d("center-left", size=0.3) # make it 2D | ||
show(man, axes=1, viewup="z") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import numpy as np | ||
from scipy.optimize import fsolve | ||
from vedo import Plotter, settings | ||
from vedo.pyplot import plot | ||
|
||
|
||
# Initial values | ||
C_init = 0 | ||
xdata = np.linspace(-3, 3, 50) | ||
|
||
|
||
# Function to solve for y given x and C (from your first script) | ||
def solve_for_y(x, C): | ||
y_vals = [] | ||
for sign in [1, -1]: # Solve for positive and negative y | ||
|
||
def equation(y): | ||
return 0.5 * y**2 + np.log(np.abs(y)) - 0.5 * x**2 - C | ||
|
||
y_initial_guess = sign * np.exp(-0.5 * x**2 - C) | ||
|
||
root = fsolve(equation, y_initial_guess)[0] | ||
if equation(root) < 1e-5: # Only accept the root if it's a valid solution | ||
y_vals.append(root) | ||
return y_vals | ||
|
||
|
||
# Generate the y values for plotting (positive and negative y) | ||
def generate_y_values(x_values, C): | ||
y_positive = [] | ||
y_negative = [] | ||
for x in x_values: | ||
y_vals = solve_for_y(x, C) | ||
if len(y_vals) > 0: | ||
y_positive.append(max(y_vals)) # Choose the largest root as positive | ||
y_negative.append(min(y_vals)) # Choose the smallest root as negative | ||
else: | ||
y_positive.append(np.nan) # Use NaN for missing values | ||
y_negative.append(np.nan) | ||
return y_positive, y_negative | ||
|
||
|
||
# Function to update the plot when the slider changes | ||
def update_plot(widget=None, event=""): | ||
C_value = C_init if widget is None else widget.value | ||
y_positive, y_negative = generate_y_values(xdata, C_value) | ||
m = max(max(y_positive), abs(min(y_negative))) | ||
p = plot(xdata, y_positive, c='red5', lw=4, ylim=(-m, m)) | ||
p += plot(xdata, y_negative, c='blue5', lw=4, like=p) | ||
plt.remove("PlotXY").add(p) | ||
|
||
|
||
# Create Plotter and the slider to control the value of C | ||
settings.default_font = "Brachium" | ||
|
||
plt = Plotter(size=(900, 650), title="Exercise") | ||
slider = plt.add_slider(update_plot, -10.0, 10.0, value=C_init, title="C value", c="green3") | ||
update_plot() # Initial plot | ||
|
||
plt.show(mode="2d", zoom=1.35) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
_version = '2024.5.2+dev12' | ||
_version = '2024.5.2+dev14' |