Repository: matplotlib/matplotlib

Issue:
Cannot access hexbin data when `xscale='log'` and `yscale='log'` are set.
### Bug report

```python
plt.hexbin([1,10,100],[1,10,100], mincnt=1).get_offsets()
plt.hexbin([1,10,100],[1,10,100], mincnt=1, xscale='log', yscale='log').get_offsets()
```

I've made a log-log hexbin plot and would like to access the points generated by `hexbin` so I can make a contour. I cannot access these points for two reasons:

1) The documentation is incorrect and states that `PolyCollection.get_offset()` should be called, but it is `PolyCollection.get_offsets()` (note plural). See 1st bullet point under `returns` here https://matplotlib.org/3.3.0/api/_as_gen/matplotlib.pyplot.hexbin.html

2) When I call `get_offsets()` if `xscale='log'` and `yscale='log'` are set, I only get `array([[0., 0.]])` rather than the points.




Discussion:
It seems that the "no hexbin data for log scale" issue still exists. Is there any update for this issue?
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear.  Thanks for your help!
Still open. Would still like to use this feature with log log plots.
The first half of the issue (documentation) is fixed. I can confirm the second half is still an issue though.



Patch:
diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py
index dc7f0c433fb4..cc6f0ba82d3a 100644
--- a/lib/matplotlib/axes/_axes.py
+++ b/lib/matplotlib/axes/_axes.py
@@ -5014,7 +5014,7 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
             A `.PolyCollection` defining the hexagonal bins.
 
             - `.PolyCollection.get_offsets` contains a Mx2 array containing
-              the x, y positions of the M hexagon centers.
+              the x, y positions of the M hexagon centers in data coordinates.
             - `.PolyCollection.get_array` contains the values of the M
               hexagons.
 
@@ -5192,7 +5192,7 @@ def reduce_C_function(C: array) -> float
             linewidths = [mpl.rcParams['patch.linewidth']]
 
         if xscale == 'log' or yscale == 'log':
-            polygons = np.expand_dims(polygon, 0) + np.expand_dims(offsets, 1)
+            polygons = np.expand_dims(polygon, 0)
             if xscale == 'log':
                 polygons[:, :, 0] = 10.0 ** polygons[:, :, 0]
                 xmin = 10.0 ** xmin
@@ -5203,20 +5203,16 @@ def reduce_C_function(C: array) -> float
                 ymin = 10.0 ** ymin
                 ymax = 10.0 ** ymax
                 self.set_yscale(yscale)
-            collection = mcoll.PolyCollection(
-                polygons,
-                edgecolors=edgecolors,
-                linewidths=linewidths,
-                )
         else:
-            collection = mcoll.PolyCollection(
-                [polygon],
-                edgecolors=edgecolors,
-                linewidths=linewidths,
-                offsets=offsets,
-                offset_transform=mtransforms.AffineDeltaTransform(
-                    self.transData),
-            )
+            polygons = [polygon]
+
+        collection = mcoll.PolyCollection(
+            polygons,
+            edgecolors=edgecolors,
+            linewidths=linewidths,
+            offsets=offsets,
+            offset_transform=mtransforms.AffineDeltaTransform(self.transData)
+        )
 
         # Set normalizer if bins is 'log'
         if cbook._str_equal(bins, 'log'):


Test patch:
diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py
index 3666b16e6dad..deeec45332d9 100644
--- a/lib/matplotlib/tests/test_axes.py
+++ b/lib/matplotlib/tests/test_axes.py
@@ -1017,6 +1017,27 @@ def test_hexbin_log():
                   marginals=True, reduce_C_function=np.sum)
     plt.colorbar(h)
 
+    # Make sure offsets are set
+    assert h.get_offsets().shape == (11558, 2)
+
+
+def test_hexbin_log_offsets():
+    x = np.geomspace(1, 100, 500)
+
+    fig, ax = plt.subplots()
+    h = ax.hexbin(x, x, xscale='log', yscale='log', gridsize=2)
+    np.testing.assert_almost_equal(
+        h.get_offsets(),
+        np.array(
+            [[0, 0],
+             [0, 2],
+             [1, 0],
+             [1, 2],
+             [2, 0],
+             [2, 2],
+             [0.5, 1],
+             [1.5, 1]]))
+
 
 @image_comparison(["hexbin_linear.png"], style="mpl20", remove_text=True)
 def test_hexbin_linear():