Comments (14)
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.
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)
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.
The line that fixes the issue is the relayout!
, so it is certainly a bug somewhere.
from plotlyjs.jl.
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.
using PlotlyJS
lon = rand(100)
lat = rand(100)
p = plot(densitymapbox(lon = lon, lat = lat))
relayout!(p, mapbox_style = "open-street-map")
p
The issue has no relation with z
.
from plotlyjs.jl.
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) ))
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.
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.
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.
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.
@empet , What do you think the role of the z
parameter?
According to the link you gave:
The parameter z
is only optional.
On the documentation of the parameter:
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.
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)
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)
from plotlyjs.jl.
from plotlyjs.jl.
@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.
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)
- Plotting fails after a couple of plot calls HOT 1
- PlotlyJs.savefig() doesn't save static image - Kaleido is not avaiable HOT 11
- Heatmap with customdata and hovertemplate doesn't display the right info, when size(customdata)=size(z)
- PlotlyJS breaks when Julia is started with multiple threads
- Bump PLOTLYJS_VERSION
- Blank Plot when plotting in browser with VSCode setting "Julia: Use Plot Pane" unchecked
- cannot create subplots of pie HOT 2
- Add `image` Type of Trace HOT 8
- PlotlyJS.image incorrectly serializes to json the z array of size (d, rows, cols) , d=3, 4
- Not all documentation source files available in repo
- Kaleido process in package initialisation hangs HOT 26
- Time series plot with period data type HOT 1
- style not defined HOT 6
- The "using PlotlyJS" execution does not finish HOT 2
- Pre-compilation does not finish with version 0.18.11 HOT 7
- Setting PlotlyJS as default backend for Plots HOT 1
- Kaleido not available on windows 11 with julia 1.10 HOT 6
- Windows error for PlotlyKaleido breaks precompilation HOT 8
- "Kaleido startup failed" in docker container HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plotlyjs.jl.