continuous-error-multiple.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 datetime
  17. from typing import Dict, List
  18. import dateutil.relativedelta
  19. from taipy.gui import Gui
  20. if __name__ == "__main__":
  21. # Data is collected from January 1st, 2010, every month
  22. start_date = datetime.datetime(year=2010, month=1, day=1)
  23. period = dateutil.relativedelta.relativedelta(months=1)
  24. # Data
  25. # All arrays have the same size (the number of months to track)
  26. prices: Dict[str, List] = {
  27. # Data for apples
  28. "apples": [2.48, 2.47, 2.5, 2.47, 2.46, 2.38, 2.31, 2.25, 2.39, 2.41, 2.59, 2.61],
  29. "apples_low": [1.58, 1.58, 1.59, 1.64, 1.79, 1.54, 1.53, 1.61, 1.65, 2.02, 1.92, 1.54],
  30. "apples_high": [3.38, 3.32, 2.63, 2.82, 2.58, 2.53, 3.27, 3.15, 3.44, 3.42, 3.08, 2.86],
  31. "bananas": [2.94, 2.50, 2.39, 2.77, 2.43, 2.32, 2.37, 1.90, 2.31, 2.71, 3.38, 1.92],
  32. "bananas_low": [2.12, 1.90, 1.69, 2.44, 1.58, 1.81, 1.44, 1.00, 1.59, 1.74, 2.78, 0.96],
  33. "bananas_high": [3.32, 2.70, 3.12, 3.25, 3.00, 2.63, 2.54, 2.37, 2.97, 3.69, 4.36, 2.95],
  34. "cherries": [6.18, None, None, None, 3.69, 2.46, 2.31, 2.57, None, None, 6.50, 4.38],
  35. "cherries_high": [7.00, None, None, None, 8.50, 6.27, 5.61, 4.36, None, None, 8.00, 7.23],
  36. "cherries_low": [3.55, None, None, None, 1.20, 0.87, 1.08, 1.50, None, None, 5.00, 4.20],
  37. }
  38. # Create monthly time series
  39. months = [start_date + n * period for n in range(0, len(prices["apples"]))]
  40. data = [
  41. # Raw data
  42. {"Months": months, "apples": prices["apples"], "bananas": prices["bananas"], "cherries": prices["cherries"]},
  43. # Range data (twice as many values)
  44. {
  45. "Months2": months + list(reversed(months)),
  46. "apples": prices["apples_high"] + list(reversed(prices["apples_low"])),
  47. "bananas": prices["bananas_high"] + list(reversed(prices["bananas_low"])),
  48. "cherries": prices["cherries_high"] + list(reversed(prices["cherries_low"])),
  49. },
  50. ]
  51. properties = {
  52. # First trace: reference for Apples
  53. "x[1]": "0/Months",
  54. "y[1]": "0/apples",
  55. "color[1]": "rgb(0,200,80)",
  56. # Hide line
  57. "mode[1]": "markers",
  58. # Show in the legend
  59. "name[1]": "Apples",
  60. # Second trace: reference for Bananas
  61. "x[2]": "0/Months",
  62. "y[2]": "0/bananas",
  63. "color[2]": "rgb(0,100,240)",
  64. # Hide line
  65. "mode[2]": "markers",
  66. # Show in the legend
  67. "name[2]": "Bananas",
  68. # Third trace: reference for Cherries
  69. "x[3]": "0/Months",
  70. "y[3]": "0/cherries",
  71. "color[3]": "rgb(240,60,60)",
  72. # Hide line
  73. "mode[3]": "markers",
  74. # Show in the legend
  75. "name[3]": "Cherries",
  76. # Fourth trace: range for Apples
  77. "x[4]": "1/Months2",
  78. "y[4]": "1/apples",
  79. "options[4]": {
  80. "fill": "tozerox",
  81. "showlegend": False,
  82. "fillcolor": "rgba(0,100,80,0.4)",
  83. },
  84. # No surrounding stroke
  85. "color[4]": "transparent",
  86. # Fifth trace: range for Bananas
  87. "x[5]": "1/Months2",
  88. "y[5]": "1/bananas",
  89. "options[5]": {"fill": "tozerox", "showlegend": False, "fillcolor": "rgba(0,180,250,0.4)"},
  90. # No surrounding stroke
  91. "color[5]": "transparent",
  92. # Sixth trace: range for Cherries
  93. "x[6]": "1/Months2",
  94. "y[6]": "1/cherries",
  95. "options[6]": {
  96. "fill": "tozerox",
  97. "showlegend": False,
  98. "fillcolor": "rgba(230,100,120,0.4)",
  99. },
  100. # No surrounding stroke
  101. "color[6]": "transparent",
  102. }
  103. page = """
  104. # Continuous Error - Multiple traces
  105. <|{data}|chart|properties={properties}|>
  106. """
  107. Gui(page).run()