advanced-python-lib.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright 2021-2024 Avaiga Private Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  4. # the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  9. # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  10. # specific language governing permissions and limitations under the License.
  11. # -----------------------------------------------------------------------------------------
  12. # To execute this script, make sure that the taipy-gui package is installed in your
  13. # Python environment and run:
  14. # python <script>
  15. # -----------------------------------------------------------------------------------------
  16. # This script needs to run in a Python environment where the plotly-express package is
  17. # installed.
  18. # -----------------------------------------------------------------------------------------
  19. import numpy as np
  20. import plotly.graph_objects as go
  21. from taipy.gui import Gui
  22. if __name__ == "__main__":
  23. # Create the Plotly figure object
  24. figure = go.Figure()
  25. # Add trace for Normal Distribution
  26. figure.add_trace(
  27. go.Violin(name="Normal", y=np.random.normal(loc=0, scale=1, size=1000), box_visible=True, meanline_visible=True)
  28. )
  29. # Add trace for Exponential Distribution
  30. figure.add_trace(
  31. go.Violin(
  32. name="Exponential", y=np.random.exponential(scale=1, size=1000), box_visible=True, meanline_visible=True
  33. )
  34. )
  35. # Add trace for Uniform Distribution
  36. figure.add_trace(
  37. go.Violin(
  38. name="Uniform", y=np.random.uniform(low=0, high=1, size=1000), box_visible=True, meanline_visible=True
  39. )
  40. )
  41. # Updating layout for better visualization
  42. figure.update_layout(title="Different Probability Distributions")
  43. page = """
  44. <|chart|figure={figure}|>
  45. """
  46. Gui(page).run()