Skip to content
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

DOC: Add zorder example to docs #1228

Merged
merged 7 commits into from
Dec 9, 2019
Merged

DOC: Add zorder example to docs #1228

merged 7 commits into from
Dec 9, 2019

Conversation

Sangarshanan
Copy link
Contributor

@Sangarshanan Sangarshanan commented Nov 30, 2019

Closes #1224

@Sangarshanan Sangarshanan changed the title Add zorder example to docs DOC: Add zorder example to docs Nov 30, 2019
@codecov
Copy link

codecov bot commented Nov 30, 2019

Codecov Report

Merging #1228 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1228   +/-   ##
=======================================
  Coverage   89.89%   89.89%           
=======================================
  Files          21       21           
  Lines        2088     2088           
=======================================
  Hits         1877     1877           
  Misses        211      211

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 22b5a0d...a75a3c3. Read the comment docs.

@martinfleis
Copy link
Member

Hi,
sorry for a slow response. I would prefer using our naturalearth_cities and naturalearth_lowres datasets for this example.

cities = geopandas.read_file(geopandas.datasets.get_path('naturalearth_cities'))
world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))

You don't need to import matplotlib, as you can make axis using one plot and reuse it for another.

ax = cities.plot(color='k')
world.plot(ax=ax)

ax = cities.plot(color='k', zorder=2)
world.plot(ax=ax, zorder=1)

I would also make a note than lower zorder = lower layer. Thanks!

@Sangarshanan
Copy link
Contributor Author

Sure...Will do that

Copy link
Member

@martinfleis martinfleis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few minor suggestions, otherwise it looks good. Thanks!

doc/source/mapping.rst Outdated Show resolved Hide resolved
doc/source/mapping.rst Outdated Show resolved Hide resolved
doc/source/mapping.rst Outdated Show resolved Hide resolved
doc/source/mapping.rst Outdated Show resolved Hide resolved
doc/source/mapping.rst Outdated Show resolved Hide resolved
doc/source/mapping.rst Outdated Show resolved Hide resolved
@Sangarshanan
Copy link
Contributor Author

Thanks for helping out : )

doc/source/mapping.rst Outdated Show resolved Hide resolved
Co-Authored-By: Martin Fleischmann <36797143+martinfleis@users.noreply.github.com>
@martinfleis
Copy link
Member

Oh, one final thing. You need to tell sphinx that images should be saved. And you were right with the header type before. My bad. I can't push changes (as you did not allow it), so pasting the correct version below.

Control the order of multiple layers in a plot
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

When plotting multiple layers, use ``zorder`` to take control of the order of layers being plotted.
The lower the ``zorder`` is, the lower the layer is on the map and vice versa.

Without specified ``zorder``, cities (Points) gets plotted below world (Polygons), following the default order based on geometry types.

.. ipython:: python

    ax = cities.plot(color='k')
    @savefig zorder_default.png
    world.plot(ax=ax);

We can set the ``zorder`` for cities higher than for world to move it of top.

.. ipython:: python

    ax = cities.plot(color='k', zorder=2)
    @savefig zorder_set.png
    world.plot(ax=ax, zorder=1);

@Sangarshanan
Copy link
Contributor Author

Oh... I have allowed edits from maintainers

I will make the change tho... Thank you for your patience

@martinfleis martinfleis merged commit 1a0376c into geopandas:master Dec 9, 2019
@martinfleis
Copy link
Member

Thank you @Sangarshanan!

lwasser pushed a commit to lwasser/geopandas that referenced this pull request Apr 8, 2020
* Add zorder examples to docs

* Remove matplotlib and make suggested changes

* Remove empty line

* Made the suggested minor changes

* Change line format

Co-Authored-By: Martin Fleischmann <36797143+martinfleis@users.noreply.github.com>

* Save the plots with savefig
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

Successfully merging this pull request may close these issues.

DOC: add explanation of using zorder to control which layers are on top
2 participants