1
0

histogram-binning-function.py 2.2 KB

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