continuous-error-simple.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # Copyright 2023 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. import random
  17. from taipy.gui import Gui
  18. # Common axis for all data: [1..10]
  19. x = list(range(1, 11))
  20. # Sample data
  21. samples = [5, 7, 8, 4, 5, 9, 8, 8, 6, 5]
  22. # Generate error data
  23. # Error that adds to the input data
  24. error_plus = [3 * random.random() + 0.5 for _ in x]
  25. # Error substracted from to the input data
  26. error_minus = [3 * random.random() + 0.5 for _ in x]
  27. # Upper bound (y + error_plus)
  28. error_upper = [y + e for (y, e) in zip(samples, error_plus)]
  29. # Lower bound (y - error_minus)
  30. error_lower = [y - e for (y, e) in zip(samples, error_minus)]
  31. data = [
  32. # Trace for samples
  33. {"x": x, "y": samples},
  34. # Trace for error range
  35. {
  36. # Roundtrip around the error bounds: onward then return
  37. "x": x + list(reversed(x)),
  38. # The two error bounds, with lower bound reversed
  39. "y": error_upper + list(reversed(error_lower)),
  40. },
  41. ]
  42. properties = {
  43. # Error data
  44. "x[1]": "1/x",
  45. "y[1]": "1/y",
  46. "options[1]": {
  47. # Shows as filled area
  48. "fill": "toself",
  49. "fillcolor": "rgba(70,70,240,0.6)",
  50. "showlegend": False,
  51. },
  52. # Don't show surrounding stroke
  53. "color[1]": "transparent",
  54. # Raw data (displayed on top of the error band)
  55. "x[2]": "0/x",
  56. "y[2]": "0/y",
  57. "color[2]": "rgb(140,50,50)",
  58. # Shown in the legend
  59. "name[2]": "Input",
  60. }
  61. page = """
  62. # Continuous Error - Simple
  63. <|{data}|chart|properties={properties}|>
  64. """
  65. Gui(page).run()