plotly / plotly/plotly.py

figure_factory create_hexbin_mapbox ignored agg_func

Open
#4,632 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3 sev-4
Dominant language
Python
Stars
18.8k
Forks
2.8k
Avg merge
16h 26m
Merged PRs (30d)
21

Description

As the title states, the aggregation function is entirely ignored and it does not make any difference whether you insert np.mean, np.min or np.max. Using plotly==5.22.0

Example:

  1. Generate data
import plotly.figure_factory as ff
import pandas as pd
import numpy as np

# Mock GeoDataFrame with latitude, longitude, and value columns
np.random.seed(0)
num_points = 1000
data = {
    'lat': np.random.uniform(40, 45, num_points),
    'lon': np.random.uniform(-75, -70, num_points),
    'value': np.random.uniform(0, 1, num_points)
}
df = pd.DataFrame(data)
df
  1. Plot and check vals

fig = ff.create_hexbin_mapbox(
    data_frame=df, lat="lat", lon="lon",
    nx_hexagon=50,  # Decrease the size of hexagons
    opacity=0.5, labels={"color": "value"},
    color_continuous_scale="Viridis",
    agg_func=np.min,  # or np.max aggregation
    show_original_data=True,
    original_data_marker=dict(size=1.1, opacity=0.6, color="deeppink")
)

# Extract the hexbin data
hexbin_data = fig.data[0]

# Check the hexbin values
print("Hexbin values (z):", hexbin_data.z)

# Update the text of each hexagon to display the maximum value
hexbin_data.hovertemplate = 'Value: %{z}<extra></extra>'

# Update the layout to use OSM tiles
fig.update_layout(
    mapbox_style="open-street-map",
    height=800  # Set the desired height
)

fig.show()

Output for np.min, np.mean and np.max is identical:

Hexbin values (z): [0. 0. 0. ... 0. 1. 0.]

Hence, the plot does not change.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the figure_factory entry point ff.create_hexbin_mapbox and reproduce the issue with the provided DataFrame and np.min, np.mean, and np.max examples. Trace how agg_func is passed into hexbin generation, then verify that the resulting hexbin_data.z values differ appropriately for each aggregation function.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, pandas, plotly, python
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.