plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
16.29k stars 2.55k forks source link

Add `scattermap` and `map` to plotly.py templates similar to `scattermapbox` and `mapbox` #4879

Open archmoj opened 1 day ago

archmoj commented 1 day ago

In order for scattermap and map behave similar to scattermapbox and mapbox, we should add scattermap and map to the templates inside packages/python/plotly/plotly/package_data/templates/.

archmoj commented 1 day ago

cc: @gvwilson @ndrezn

archmoj commented 1 day ago

Are there similar defaults in ddk that should be updated?

gvwilson commented 1 day ago

Are the .json files in packages/python/plotly/plotly/package_data/templates/ generated by a script? If so, what script and where does the data come from? (the compact formatting of these .json files leads me to believe they aren't hand-edited.)

  1. packages/python/plotly/setup.py refers to package_data/templates/*.
  2. packages/python/plotly/templategen/* seems to be the generator.
archmoj commented 1 day ago

@LiamConnors Are these templates auto generated?

archmoj commented 1 day ago

We should add map alternatives e.g. here and in other places similar to mapbox.

gvwilson commented 1 day ago

It appears that templategen is invoked manually rather than automatically.

gvwilson commented 1 day ago

Progress of a sort. Please note that I'm working off the master branch, which may not have the most up-to-date files.

  1. Modified packages/python/plotly/templategen/utils/__init__.py to change template.data.heatmapgl[0] to template.data.heatmap[0]. (Step 3 fails without this change.)
  2. Moved the interesting bits of packages/python/plotly/templategen/__init__.py to packages/python/plotly/templategen/__main__.py so that we can run python -m templategen from the packages/python/plotly/templategen directory.
  3. Ran that command, which generated new versions of these six files:
    • plotly/package_data/templates/ggplot2.json
    • plotly/package_data/templates/plotly.json
    • plotly/package_data/templates/plotly_dark.json
    • plotly/package_data/templates/plotly_white.json
    • plotly/package_data/templates/seaborn.json
    • plotly/package_data/templates/simple_white.json
  4. Note that this command did not generate new versions of gridon.json, presentation.json, xgridoff.json, or ygridoff.json - I don't know why.

I'm attaching pretty-printed versions of the old and new versions of plotly.json. The only difference is that the new version has an entry for scattermap as well as scattermapbox, while the old version only had scattermapbox. Note that I have not added map since there wasn't an entry for mapbox, and that I didn't have to add scattermap (it was already there).

new-plotly-indented.json

old-plotly-indented.json

archmoj commented 1 day ago

Thanks @gvwilson That's a good progress to help continue automation of this process. Are you going to open a pull request? If so on master please git pull switch to have the latest files. Then please switch to a new branch other than master and and rerun the script and commit the changes. You may consider skipping the pretty-print step in your PR specially if that helps the diffs to be clearer.

gvwilson commented 1 day ago

I've created a new branch off master with my changes called add-new-traces-to-templategen - @archmoj please take it from here.