Coder Social home page Coder Social logo

Comments (14)

empet avatar empet commented on May 27, 2024 2

Python version works in this case (of densitymapbox) like PlotlyJS.
These lines of python code:

import plotly.graph_objects as go
fig = go.Figure(go.Densitymapbox(lat=[-1, 1],  lon=[177, 179]))
fig.show()

don't display anything, because go.Densitymapbox works only when the user has set
his/her favorite mapbox_style (some styles can be accessed only with the user's mapbox_token).
You are interpreting the actual behaviour of densitymapbox as an issue, because the Layout isn't predefined. Plotly.py and hence its version, PlotlyJS, doesn't prescribe the Layout for any plot (no recipes!!!). Each Figure instance contains two objects: the trace and the layout. Then the user, according to his/her data, goal, inspiration and creativity, is setting the attributes leading to the final plot.
plotly.py, PlotlyJS.jl, R, javascript have a detailed reference site for traces and layout
(here is for Julia: https://plotly.com/julia/reference/index/),
and moreover, examples (docs) for different traces: https://plotly.com/julia/. The docs for versions of PlotlyJS.jl before 0.18 are outdated.

from plotlyjs.jl.

empet avatar empet commented on May 27, 2024

You did not give any values to be mapped to a colorscale in order to get a density.
Here is the reference for densitymapbox https://plotly.com/julia/reference/densitymapbox/
and this is an example:

using HTTP, CSV, DataFrames, PlotlyJS
res = HTTP.get("https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv")
df = CSV.read(res.body, DataFrame);

fig = Plot(densitymapbox(lat=df[!, :Latitude], lon=df[!, :Longitude],
                         z=df[:, :Magnitude], radius=10, 
                         colorscale=reverse(colors.matter),
                        ))
relayout!(fig, mapbox_style="open-street-map", mapbox_center_lon=68, mapbox_center_lat=29)  
display(fig)

densitymapbox

LE: To display on hover all information contained in the dataframe, you should include customdata and hovertemplate in the trace definition:

fig = Plot(densitymapbox(lat=df[!, :Latitude], lon=df[!, :Longitude],
                         z=df[:, :Magnitude], radius=10, customdata = df[!, :Date],
                         hovertemplate="lon: %{lon}<br>lat: %{lat}<br>date: %{customdata}<br>magnit: %{z}<extra></extra>",
                         colorscale=reverse(colors.matter),
                        ))

from plotlyjs.jl.

juliohm avatar juliohm commented on May 27, 2024

The line that fixes the issue is the relayout!, so it is certainly a bug somewhere.

from plotlyjs.jl.

empet avatar empet commented on May 27, 2024

Your MWE contained just plot(densitymapbox(lon = lon, lat = lat)). I don't think that without adding z-values, only relayout you get a density plot that displays the right data in the dataframe.

from plotlyjs.jl.

juliohm avatar juliohm commented on May 27, 2024
using PlotlyJS

lon = rand(100)
lat = rand(100)

p = plot(densitymapbox(lon = lon, lat = lat))

relayout!(p, mapbox_style = "open-street-map")

p

image

The issue has no relation with z.

from plotlyjs.jl.

empet avatar empet commented on May 27, 2024

But without z the generated plot has NO meaning.
For my example, if I define the trace without z:

fig = Plot(densitymapbox(lat=df[!, :Latitude], lon=df[!, :Longitude],
            colorscale=reverse(colors.matter) ))

I get this plot:
densitymapboxnoz

What does it represent? Compare with the first densitymapbox.! Heatmaps, contour plots and here densitymapbox need z-values to be mapped to a colorscheme.

from plotlyjs.jl.

juliohm avatar juliohm commented on May 27, 2024

A density map doesn't require z values. The density is computed based on the proximity of points in the map. The z values are just an option to adjust the heights of the density.

The issue I am reporting above has no relation with the specification of the z attribute. It is about the layout that is not set correctly by default.

To fix the issue one has to manually call relayout! or provide a layout in the plot command with the same mapbox options:

plot(densitymapbox(...), Layout(....))

from plotlyjs.jl.

empet avatar empet commented on May 27, 2024

I'm sure you know what is a density. It's not the density of geographic locations, but the density of values associated to them. The mapbox layout cannot be set directly, by default, because each user wants to display a particular region of the globe, and so with different mapbox centers.
I'm stopping this discussion. :)

from plotlyjs.jl.

juliohm avatar juliohm commented on May 27, 2024

So you mean that the current behavior is acceptable? I believe that this is very bogus without the actual density being displayed by default.

The density of geographic locations is a particular case of density estimation with constant z value. We have tons of similar interpolation methods in our GeoStats.jl stack, and know in depth all the details that go into density estimation.

I feel that the PlotlyJS.jl behavior is buggy, and that beginners will struggle producing the simplest maps when nothing is shown by default. If the trace is called densitymapbox, then the attributes of the layout should be set for mapbox by default. Setting style = "open-street-map" is enough to fix the bug.

from plotlyjs.jl.

RoyiAvital avatar RoyiAvital commented on May 27, 2024

@empet , What do you think the role of the z parameter?

According to the link you gave:

image

The parameter z is only optional.
On the documentation of the parameter:

image

It says the parameter is basically a weight of the corresponding point.
So the values to be scaled does not require z, no?

It might be an issue of PlotLy itself and not PlotLyJS.jl.

from plotlyjs.jl.

empet avatar empet commented on May 27, 2024

Yes you may use it without z-values, but with NO MEANING. Look here at a geographical region
within Pacific Ocean (no island around), with lon, lat, at a distance of two units, and
and two locations at a smaller distance around Paris. We get the same density.
How do you interpret this similarity between the two densities?

fig1 = Plot(densitymapbox(lat=[-1, 1],  lon=[177, 179]))
relayout!(fig1, mapbox_style="open-street-map", mapbox_center_lon=160, mapbox_center_lat=0,
                  width=600, height=350)

ocean

fig2 = Plot(densitymapbox(lat=[48.25, 49],  lon=[2, 2.5]))
relayout!(fig2, mapbox_style="open-street-map", mapbox_center_lon=2.25, mapbox_center_lat=48.5,
                  width=600, height=350)  

Paris

from plotlyjs.jl.

juliohm avatar juliohm commented on May 27, 2024

from plotlyjs.jl.

RoyiAvital avatar RoyiAvital commented on May 27, 2024

@empet , I have little knowledge about the geographical things.
If it is a standard 2D KDE, and z is, as documented, just the weight, it should work with the same meaning.
As any KDE the output is a balance of bias / variance tradeoff between the local resolution and the accuracy of the estimation.
The case with no z should be equivalent to the case all z are equal and it is a valid weighing.

Yet I think the point of the issue is why the layout is required and it doesn't work without it.

Then the question is whether it is specific to PlotLyJS.jl or something in PlotLy itself.

@juliohm , You may try the same in Python.
If it behaves the same as you pointed, the issue is in PlotLy, otherwise, it is in PlotLyJS.jl (Most likely).

from plotlyjs.jl.

juliohm avatar juliohm commented on May 27, 2024

I will close the issue given that the bug is in the underlying Javascript library. It feels very unpolished, the typical Javascript experience.

from plotlyjs.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.