{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "When "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "density"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is True, then the returned histogram is the sample density, defined such that the sum over bins of the product "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "bin_value * bin_area"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is 1."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Please note that the histogram does not follow the Cartesian convention where "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " values are on the abscissa and "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "y"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " values on the ordinate axis.  Rather, "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is histogrammed along the first dimension of the array (vertical), and "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "y"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " along the second dimension of the array (horizontal).  This ensures compatibility with "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "histogramdd",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Raises": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Yields": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Methods": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Returns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "H",
              "annotation": "ndarray, shape(nx, ny)",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The bi-dimensional histogram of samples "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "y"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Values in "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " are histogrammed along the first dimension and values in "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "y"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " are histogrammed along the second dimension."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "xedges",
              "annotation": "ndarray, shape(nx+1,)",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The bin edges along the first dimension."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "yedges",
              "annotation": "ndarray, shape(ny+1,)",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The bin edges along the second dimension."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Compute the bi-dimensional histogram of two data samples."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Receives": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warnings": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Attributes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "x",
              "annotation": "array_like, shape (N,)",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "An array containing the x coordinates of the points to be histogrammed."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "y",
              "annotation": "array_like, shape (N,)",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "An array containing the y coordinates of the points to be histogrammed."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "bins",
              "annotation": "int or array_like or [int, int] or [array, array], optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The bin specification:"
                    }
                  ]
                },
                {
                  "__type": "BulletList",
                  "__tag": 4053,
                  "ordered": false,
                  "start": 1,
                  "children": [
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "If int, the number of bins for the two dimensions (nx=ny=bins)."
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "If array_like, the bin edges for the two dimensions   (x_edges=y_edges=bins)."
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "If [int, int], the number of bins in each dimension   (nx, ny = bins)."
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "If [array, array], the bin edges in each dimension   (x_edges, y_edges = bins)."
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "A combination [int, array] or [array, int], where int   is the number of bins and array is the bin edges."
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "range",
              "annotation": "array_like, shape(2,2), optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The leftmost and rightmost edges of the bins along each dimension (if not specified explicitly in the "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "bins"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " parameters): "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "[[xmin, xmax], [ymin, ymax]]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". All values outside of this range will be considered outliers and not tallied in the histogram."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "density",
              "annotation": "bool, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If False, the default, returns the number of samples in each bin. If True, returns the probability "
                    },
                    {
                      "__type": "Emphasis",
                      "__tag": 4047,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "density"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " function at the bin, "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "bin_count / sample_count / bin_area"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "weights",
              "annotation": "array_like, shape(N,), optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "An array of values "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "w_i"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " weighing each sample "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "(x_i, y_i)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Weights are normalized to 1 if "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "density"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is True. If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "density"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is False, the values of the returned histogram are equal to the sum of the weights belonging to the samples falling into each bin."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Other Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    }
  },
  "_ordered_sections": [
    "Summary",
    "Extended Summary",
    "Parameters",
    "Attributes",
    "Methods",
    "Returns",
    "Yields",
    "Receives",
    "Other Parameters",
    "Raises",
    "Warns",
    "Warnings",
    "Notes"
  ],
  "item_file": "/numpy/lib/_twodim_base_impl.py",
  "item_line": 668,
  "item_type": "_ArrayFunctionDispatcher",
  "aliases": [
    "numpy.histogram2d"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nfrom matplotlib.image import NonUniformImage\nimport matplotlib.pyplot as plt\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nConstruct a 2-D histogram with variable bin width. First define the bin\nedges:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "xedges = [0, 1, 3, 5]\nyedges = [0, 2, 3, 4, 6]\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nNext we create a histogram H with random bin content:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "x = np.random.normal(2, 1, 100)\ny = np.random.normal(1, 1, 100)\nH, xedges, yedges = np.histogram2d(x, y, bins=(xedges, yedges))\nH = H.T\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\n:func:`imshow <matplotlib.pyplot.imshow>` can only display square bins:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "fig = plt.figure(figsize=(7, 3))\nax = fig.add_subplot(131, title='imshow: square bins')\nplt.imshow(H, interpolation='nearest', origin='lower',\n        extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]])\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\n:func:`pcolormesh <matplotlib.pyplot.pcolormesh>` can display actual edges:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax = fig.add_subplot(132, title='pcolormesh: actual edges',\n        aspect='equal')\nX, Y = np.meshgrid(xedges, yedges)\nax.pcolormesh(X, Y, H)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\n:class:`NonUniformImage <matplotlib.image.NonUniformImage>` can be used to\ndisplay actual bin edges with interpolation:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax = fig.add_subplot(133, title='NonUniformImage: interpolated',\n        aspect='equal', xlim=xedges[[0, -1]], ylim=yedges[[0, -1]])\nim = NonUniformImage(ax, interpolation='bilinear')\nxcenters = (xedges[:-1] + xedges[1:]) / 2\nycenters = (yedges[:-1] + yedges[1:]) / 2\nim.set_data(xcenters, ycenters, H)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax.add_image(im)\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.show()\n",
        "execution_status": "success"
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "numpy",
          "version": "2.4.4",
          "kind": "assets",
          "path": "fig-bbfba3d8ef190340.png"
        }
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nIt is also possible to construct a 2-D histogram without specifying bin\nedges:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "n = 10000\nx = np.linspace(1, 100, n)\ny = 2*np.log(x) + np.random.rand(n) - 0.5\nH, yedges, xedges = np.histogram2d(y, x, bins=20)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nNow we can plot the histogram using\n:func:`pcolormesh <matplotlib.pyplot.pcolormesh>`, and a\n:func:`hexbin <matplotlib.pyplot.hexbin>` for comparison.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "fig, (ax1, ax2) = plt.subplots(ncols=2, sharey=True)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax1.pcolormesh(xedges, yedges, H, cmap='rainbow')\nax1.plot(x, 2*np.log(x), 'k-')\nax1.set_xlim(x.min(), x.max())\nax1.set_ylim(y.min(), y.max())\nax1.set_xlabel('x')\nax1.set_ylabel('y')\nax1.set_title('histogram2d')\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax1.grid()\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax2.hexbin(x, y, gridsize=20, cmap='rainbow')\nax2.plot(x, 2*np.log(x), 'k-')\nax2.set_title('hexbin')\nax2.set_xlim(x.min(), x.max())\nax2.set_xlabel('x')\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax2.grid()\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.show()\n",
        "execution_status": "success"
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "numpy",
          "version": "2.4.4",
          "kind": "assets",
          "path": "fig-bf0eaf0838ef3826.png"
        }
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "histogram",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "numpy:histogram2d"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "1D histogram"
            }
          ]
        }
      ],
      "type": null
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "histogramdd",
        "reference": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "current-module",
          "version": "current-version",
          "kind": "to-resolve",
          "path": "histogramdd"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Multidimensional histogram"
            }
          ]
        }
      ],
      "type": null
    }
  ],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "x",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "y",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "bins",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "10"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "range",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "density",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "weights",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "histogram2d"
  },
  "references": null,
  "qa": "numpy:histogram2d",
  "arbitrary": [],
  "local_refs": [
    "H",
    "bins",
    "density",
    "range",
    "weights",
    "x",
    "xedges",
    "y",
    "yedges"
  ]
}