histogram-binning-function.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. from taipy.gui import Gui
  17. # Initial data set. y = count_of(x)
  18. samples = {"x": ["Apples", "Apples", "Apples", "Oranges", "Bananas", "Oranges"], "y": [5, 10, 3, 8, 5, 2]}
  19. # Create a data set array to allow for two traces
  20. data = [samples, samples]
  21. # Gather those settings in a single dictionary
  22. properties = {
  23. # 'x' of the first trace is the 'x' data from the first element of data
  24. "x[1]": "0/x",
  25. # 'y' of the first trace is the 'y' data from the first element of data
  26. "y[1]": "0/y",
  27. # 'x' of the second trace is the 'x' data from the second element of data
  28. "x[2]": "1/x",
  29. # 'y' of the second trace is the 'y' data from the second element of data
  30. "y[2]": "1/y",
  31. # Data set colors
  32. "color": ["#cd5c5c", "#505070"],
  33. # Data set names (for the legend)
  34. "name": ["Count", "Sum"],
  35. # Configure the binning functions
  36. "options": [
  37. # First trace: count the bins
  38. {"histfunc": "count"},
  39. # Second trace: sum the bin occurences
  40. {"histfunc": "sum"},
  41. ],
  42. # Set x axis name
  43. "layout": {"xaxis": {"title": "Fruit"}},
  44. }
  45. page = """
  46. # Histogram - Binning function
  47. <|{data}|chart|type=histogram|properties={properties}|>
  48. """
  49. Gui(page).run()