Skip to content

[bug(?)] Markers not showing when changing symbol in Scattermapbox #891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
HaraldHeitmann opened this issue Dec 4, 2017 · 11 comments
Closed

Comments

@HaraldHeitmann
Copy link

HaraldHeitmann commented Dec 4, 2017

I was trying to do a Scattermapbox with different marker symbols, and they didn't render, at first I thought it was a Dash problem, but then I reproduce the same problem without dash (just plotly).
You can find some code to reproduce the error in the following link:

stack overflow question

@cldougl
Copy link
Member

cldougl commented Dec 4, 2017

Hi there,
You can find more options about setting the marker for scattermapbox here: https://plot.ly/python/reference/#scattermapbox-marker
Note, this trace does not behave exactly like typical plotly.js scatter traces as it uses mapbox: https://www.mapbox.com/

@cldougl cldougl closed this as completed Dec 4, 2017
@HaraldHeitmann
Copy link
Author

Thank you!
Just to clarify, the issue was that I was setting a color and a size, to a symbol which isn't a circle, so it wasn't working properly?

@cldougl
Copy link
Member

cldougl commented Dec 4, 2017

no problem, to help clarify:
https://plot.ly/python/reference/#scattermapbox-marker-symbol: Sets the marker symbol. Full list: https://www.mapbox.com/maki-icons/ Note that the array marker.color and marker.size are only available for "circle" symbols.

so the 2 issues you may be running into are:
a. color and size are only available when symbol is set to circle.
b. the typical "plotly" symbols, (ie: https://plot.ly/python/reference/#scatter-marker-symbol) are not available for this trace type, instead you can find options and further instructions at the mapbox link: https://www.mapbox.com/maki-icons/

@andreapiso
Copy link

I am not trying to set color and size but still the custom markers do not render when I select something else than the default, for example "diamond". Can we re-open this issue?

@joeflack4
Copy link

Description

I have same problem in R. I have a shiny app w/ mapbox, and a choropleth. When I add markers, I get discrete colors just fine, but two things I can't do:

  1. Not related to this issue: I can't get continuous color scale
  2. Related: I can't get symbols to show up

Code

    fig = plot_mapbox()
    # POLYGONS
      fig = fig %>% add_sf(
        data=districts,
        split=~DISTRICT,
        color=~log10(get(
          input$multi_indicator_districts.selectors.colorBy)),
        alpha=0.7,
        showlegend=FALSE)
    fig = fig %>% add_trace(
      type='scattermapbox',
      mode='markers',
      data=facilities,
      x=~longitude,
      y=~latitude,
      # split=~tier,  # discrete colors; renders just fine
      symbol=~tier,
      alpha=0.9,
      showlegend=TRUE)
    
    fig = fig %>% layout(
      mapbox=list(
        zoom=4,
        style='open-street-map'))

W/ symbols off, markers appear

Screen Shot 2021-05-19 at 7 49 47 PM

W/ symbols on, don't appear

Strangely, it looks like it's also trying to color the symbols even though I'm not asking it to do so.
Screen Shot 2021-05-19 at 9 06 25 PM

@dancassin
Copy link

I know this is over two years later, but I had the same issue recently and found my solution. You have the wrong mapbox style selected. The mapbox symbols do not work with the "carto-positron" style or "open-street-map".

In order for symbols to work, you need to use the following mapbox styles (in addition to having a free Mapbox account with a public key):

  • basic
  • streets
  • outdoors
  • light
  • dark
  • satellite
  • satellite-streets

Reference
https://plotly.com/python/scattermapbox/#set-marker-symbols

@Sajjad-Mahmoudi
Copy link

I know this is over two years later, but I had the same issue recently and found my solution. You have the wrong mapbox style selected. The mapbox symbols do not work with the "carto-positron" style or "open-street-map".

In order for symbols to work, you need to use the following mapbox styles (in addition to having a free Mapbox account with a public key):

  • basic
  • streets
  • outdoors
  • light
  • dark
  • satellite
  • satellite-streets

Reference https://plotly.com/python/scattermapbox/#set-marker-symbols

It doesn't work. Only circle is rendered.

@joeflack4
Copy link

I'm working on this project anymore but I can forward the solution if there is one.
@Sajjad-Mahmoudi No luck, eh? Did you try every one of those options?

@Sajjad-Mahmoudi
Copy link

Sajjad-Mahmoudi commented Aug 25, 2023

I'm working on this project anymore but I can forward the solution if there is one. @Sajjad-Mahmoudi No luck, eh? Did you try every one of those options? @joeflack4

Hi, below is the code snippet:
px.set_mapbox_access_token(my_token)
fig = px.scatter_mapbox(data_frame=dff_exploded,
lat="lat", lon="lon",
zoom=6,
mapbox_style="outdoors", # "basic", "outdoors", "satellite-streets", "light"
# hover_name="facilities" + ": " + "n_trials",
width=1500,
height=700,
hover_data={'lat': False, 'lon': False, 'facilities': True, 'n_trials': True},
)
fig.update_traces(cluster=dict(enabled=True,
maxzoom=12,
color='#FF3333',
size=15,
opacity=1,
),
marker=dict(opacity=1,
symbol='circle', # marker
size=10,
color='blue',
),
hovertemplate="%{customdata[2]}: %{customdata[3]}"
)
So, I tried all the recommended solutions to change the marker from "circle" to "marker" and some others, but only "circle" marker is overlayed on the map.

@dancassin
Copy link

dancassin commented Aug 25, 2023

Try removing the mapbox info from the original px.scatter_mapbox call. Also be sure the map_box style works with different symbols. Not all do. Also, not all of the symbols are currently working. I know "streets" and "triangle" work together, so I've included it below in an excerpt of my working code.

fig.add_trace(
                go.Scattermapbox(
                    lat=df.lat,
                    lon=df.lon,
                    customdata=df[["name", "address"]],
                    hovertemplate="%{customdata[0]}<br>%{customdata[1]}",
                    name="",
                    mode="markers",
                    marker=dict(
                        symbol="triangle",
                        size=8,
                    ),
                    showlegend=False,
                ),
            )
fig.update_layout(
            mapbox=dict(
                accesstoken=mapbox_token,
            ),
            mapbox_style="streets",
        )

@gaardhus
Copy link

I think raising a warning for the user when they specify both symbol and color attributes for their markers would be a nice addition in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants