{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/giswqs/geemap/blob/master/examples/notebooks/79_chart_histogram.ipynb)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Uncomment the following line to install [geemap](https://geemap.org) if needed." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# !pip install geemap" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Install the necessary libraries." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ee\n", "import geemap\n", "import geemap.chart as chart" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Initialize GEE." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.ee_initialize()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set the data and plot options." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "source = ee.ImageCollection('OREGONSTATE/PRISM/Norm81m').toBands()\n", "region = ee.Geometry.Rectangle(-123.41, 40.43, -116.38, 45.14)\n", "my_sample = source.sample(region, 5000)\n", "property = '07_ppt'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "options = {\"title\": 'July Precipitation Distribution for NW USA',\n", " \"xlabel\": 'Precipitation (mm)',\n", " \"ylabel\": 'Pixel count',\n", " \"colors\": ['#1d6b99']\n", " }" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Generate histogram with default number of bins:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "chart.feature_histogram(my_sample, property, **options)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](https://i.imgur.com/zgzpfvb.gif)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Generate histogram and set a maximum number of bins:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "chart.feature_histogram(my_sample, property, maxBuckets=30, **options)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](https://i.imgur.com/WV7aB1e.gif)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Generate histogram and set a minimum bin size:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "chart.feature_histogram(my_sample, property, minBucketWidth=0.5, **options)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Generate histogram, set a maximum number of bins and a minimum bin size:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "chart.feature_histogram(my_sample, property, minBucketWidth=3, maxBuckets=30, **options)" ] } ], "metadata": { "hide_input": false, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 5 }