test_interactive_plotxy1.py 762 B

1234567891011121314151617181920212223
  1. """Interactive plot with a slider
  2. to change the k value of a sigmoid function."""
  3. import numpy as np
  4. from vedo import Plotter, settings
  5. from vedo.pyplot import plot
  6. kinit = 0.75
  7. n = 3
  8. x = np.linspace(-1, 1, 100)
  9. def update_plot(widget=None, event=""):
  10. k = widget.value if widget else kinit
  11. # y = 1/(1 + (k/x)**n) # hill function
  12. # y = np.abs(k*x)**n *np.sign(k*x) # power law
  13. y = (2 / (1 + np.exp(-np.abs(n*k*x))) - 1) *np.sign(k*x) # sigmoid
  14. p = plot(x, y, c='red5', lw=4, xlim=(-1,1), ylim=(-1,1), aspect=1)
  15. plt.remove("PlotXY").add(p)
  16. settings.default_font = "Roboto"
  17. plt = Plotter(size=(900, 1050))
  18. plt.add_slider(update_plot, -1, 1, value=kinit, title="k value", c="red3")
  19. update_plot()
  20. plt.show(__doc__, mode="2d", zoom='tight')