continuous-error-multiple.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 datetime
  17. import dateutil.relativedelta
  18. from taipy.gui import Gui
  19. # Data is collected from January 1st, 2010, every month
  20. start_date = datetime.datetime(year=2010, month=1, day=1)
  21. period = dateutil.relativedelta.relativedelta(months=1)
  22. # Data
  23. # All arrays have the same size (the number of months to track)
  24. prices = {
  25. # Data for apples
  26. "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],
  27. "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],
  28. "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],
  29. "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],
  30. "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],
  31. "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],
  32. "cherries": [6.18, None, None, None, 3.69, 2.46, 2.31, 2.57, None, None, 6.50, 4.38],
  33. "cherries_high": [7.00, None, None, None, 8.50, 6.27, 5.61, 4.36, None, None, 8.00, 7.23],
  34. "cherries_low": [3.55, None, None, None, 1.20, 0.87, 1.08, 1.50, None, None, 5.00, 4.20],
  35. }
  36. # Create monthly time series
  37. months = [start_date + n * period for n in range(0, len(prices["apples"]))]
  38. data = [
  39. # Raw data
  40. {"Months": months, "apples": prices["apples"], "bananas": prices["bananas"], "cherries": prices["cherries"]},
  41. # Range data (twice as many values)
  42. {
  43. "Months2": months + list(reversed(months)),
  44. "apples": prices["apples_high"] + list(reversed(prices["apples_low"])),
  45. "bananas": prices["bananas_high"] + list(reversed(prices["bananas_low"])),
  46. "cherries": prices["cherries_high"] + list(reversed(prices["cherries_low"])),
  47. },
  48. ]
  49. properties = {
  50. # First trace: reference for Apples
  51. "x[1]": "0/Months",
  52. "y[1]": "0/apples",
  53. "color[1]": "rgb(0,200,80)",
  54. # Hide line
  55. "mode[1]": "markers",
  56. # Show in the legend
  57. "name[1]": "Apples",
  58. # Second trace: reference for Bananas
  59. "x[2]": "0/Months",
  60. "y[2]": "0/bananas",
  61. "color[2]": "rgb(0,100,240)",
  62. # Hide line
  63. "mode[2]": "markers",
  64. # Show in the legend
  65. "name[2]": "Bananas",
  66. # Third trace: reference for Cherries
  67. "x[3]": "0/Months",
  68. "y[3]": "0/cherries",
  69. "color[3]": "rgb(240,60,60)",
  70. # Hide line
  71. "mode[3]": "markers",
  72. # Show in the legend
  73. "name[3]": "Cherries",
  74. # Fourth trace: range for Apples
  75. "x[4]": "1/Months2",
  76. "y[4]": "1/apples",
  77. "options[4]": {
  78. "fill": "tozerox",
  79. "showlegend": False,
  80. "fillcolor": "rgba(0,100,80,0.4)",
  81. },
  82. # No surrounding stroke
  83. "color[4]": "transparent",
  84. # Fifth trace: range for Bananas
  85. "x[5]": "1/Months2",
  86. "y[5]": "1/bananas",
  87. "options[5]": {"fill": "tozerox", "showlegend": False, "fillcolor": "rgba(0,180,250,0.4)"},
  88. # No surrounding stroke
  89. "color[5]": "transparent",
  90. # Sixth trace: range for Cherries
  91. "x[6]": "1/Months2",
  92. "y[6]": "1/cherries",
  93. "options[6]": {
  94. "fill": "tozerox",
  95. "showlegend": False,
  96. "fillcolor": "rgba(230,100,120,0.4)",
  97. },
  98. # No surrounding stroke
  99. "color[6]": "transparent",
  100. }
  101. page = """
  102. # Continuous Error - Multiple traces
  103. <|{data}|chart|properties={properties}|>
  104. """
  105. Gui(page).run()