continuous-error-simple.py 2.5 KB

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