Opened 8 years ago

Closed 8 years ago

Last modified 6 years ago

#14175 closed defect (fixed)

More plot options for polytopes

Reported by: nthiery Owned by: mhampton
Priority: major Milestone: sage-5.9
Component: geometry Keywords:
Cc: sage-combinat Merged in: sage-5.9.beta0
Authors: Volker Braun, Nicolas M. Thiéry Reviewers: Volker Braun, Nicolas M. Thiéry
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by jdemeyer)

This ticket implements plot options to control the graphical display of polygons:

    def plot(self, 
             point={}, line={}, polygon={},
             wireframe={}, fill={},
             **kwds):
        """
        Return a graphical representation.

        INPUT:

        - ``point``, ``line``, ``polygon`` -- Parameters to pass to
          point (0d), line (1d), and polygon (2d) plot
          commands. Allowed values are

          * Python dictionary: Passed as keywords to the plot
            commands.

          * String or triple of numbers: The color. This is equivalent
            to passing the dictionary ``{'color':...}``.
          
          * ``None`` or ``False``: Switch off drawing of the
            corresponding graphics options.

        - ``wireframe``, ``fill`` -- Similar to ``point`` / ``line`` /
          ``polygon``, but ``fill`` is used for the graphics objects
          in the dimension of the polytope and ``wireframe`` is used
          for all lower-dimensional graphics objects.

        - ``**kwds`` -- optional keyword parameters that are passed to
          all graphics objectcs.

        OUTPUT:

        A graphics object.

        TESTS::

            sage: square = polytopes.n_cube(2)
            sage: plt = square.plot()
            sage: for p in plt:
            ...       print p.options()['rgbcolor'], p
            (0, 0, 1) Point set defined by 4 point(s)
            (0, 0, 1) Line defined by 2 points
            (0, 0, 1) Line defined by 2 points
            (0, 0, 1) Line defined by 2 points
            (0, 0, 1) Line defined by 2 points
            (0, 1, 0) Polygon defined by 4 points

        Draw the lines in red and nothing else::

            sage: plt = square.plot(point=None, line='red', polygon=False)
            sage: for p in plt:
            ...       print p.options()['rgbcolor'], p
            red Line defined by 2 points
            red Line defined by 2 points
            red Line defined by 2 points
            red Line defined by 2 points

        Draw vertices in red, no lines, and a blue polygon::

            sage: plt = square.plot(point={'color':'red'}, line=False, fill=(0,0,1))
            sage: for p in plt:
            ...       print p.options()['rgbcolor'], p
            red Point set defined by 4 point(s)
            (0, 0, 1) Polygon defined by 4 points
        """

Apply trac_14175_plot_options.patch

Attachments (1)

trac_14175_plot_options.patch (11.7 KB) - added by nthiery 8 years ago.

Download all attachments as: .zip

Change History (29)

comment:1 Changed 8 years ago by nthiery

  • Summary changed from Fix color option for 2D polyhedron to Fix warning in color option for 2D polyhedron

comment:2 Changed 8 years ago by nthiery

This is needed for #4327. Thanks!

comment:3 Changed 8 years ago by nthiery

  • Status changed from new to needs_review

comment:4 follow-up: Changed 8 years ago by vbraun

By default the outline should be drawn in a different color than the fill for visual contrast.

comment:5 in reply to: ↑ 4 Changed 8 years ago by nthiery

Replying to vbraun:

By default the outline should be drawn in a different color than the fill for visual contrast.

Is this a comment about #14781?

comment:6 follow-up: Changed 8 years ago by vbraun

No, about this ticket. So far, interior=green and outline=blue. With this patch everything is blue by default.

comment:7 in reply to: ↑ 6 Changed 8 years ago by nthiery

Replying to vbraun:

No, about this ticket. So far, interior=green and outline=blue. With this patch everything is blue by default.

Oops, I had missed the default option for the interior! What about this new version of this patch?

Cheers,

Nicolas

comment:8 Changed 8 years ago by nthiery

Actually, I also needed that for 3D. The uploaded patch handles this!

comment:9 follow-up: Changed 8 years ago by ncohen

Hellooooooooooooooooooo !!!

It looks like there is absolutely no way to guess from looking at [1] which options are accepted by all these methods... Would it be possible to add a list of them, or at least a pointer toward a place where those options are defined ?

Nathann

[1] http://www.sagemath.org/doc/reference/sage/geometry/polyhedron/plot.html

comment:10 in reply to: ↑ 9 ; follow-up: Changed 8 years ago by nthiery

Replying to ncohen:

Hellooooooooooooooooooo !!!

It looks like there is absolutely no way to guess from looking at [1] which options are accepted by all these methods... Would it be possible to add a list of them, or at least a pointer toward a place where those options are defined ?

Nathann

[1] http://www.sagemath.org/doc/reference/sage/geometry/polyhedron/plot.html

That would be nice indeed! But that's for another ticket :-)

comment:11 in reply to: ↑ 10 ; follow-up: Changed 8 years ago by ncohen

That would be nice indeed! But that's for another ticket :-)

....

Another ticket will add the documentation of an option that you make available in this one ?

Nathann

comment:12 follow-up: Changed 8 years ago by vbraun

As you remarked on #14181, this is not quite correct. If you have a 1-d polyhedron in 2-d ambient space then the fill color (and not the outline color) should apply to the line.

comment:13 in reply to: ↑ 12 Changed 8 years ago by nthiery

Replying to vbraun:

As you remarked on #14181, this is not quite correct. If you have a 1-d polyhedron in 2-d ambient space then the fill color (and not the outline color) should apply to the line.

All I need for #4327 is to be able to specify the color for all of the polyhedron. The patch implements just that, and leaves things as they were before the patch otherwise. If someone wants to go further and allow for customizing both the fill color and the ouline color, please go ahead!

But I for myself need to focus on those things were I am already way too late (like #4327, and more importantly the functorial construction patch.

Cheers,

Nicolas

comment:14 in reply to: ↑ 11 Changed 8 years ago by nthiery

Replying to ncohen:

Another ticket will add the documentation of an option that you make available in this one ?

It's documented and tested at a low level. I let Volker decide whether we want to advertise it right now at a high level, or wait until the interface is set in stone.

Cheers,

Nicolas

comment:15 follow-up: Changed 8 years ago by vbraun

Ok I'll work this over a bit.

comment:16 in reply to: ↑ 15 Changed 8 years ago by nthiery

Replying to vbraun:

Ok I'll work this over a bit.

Thanks, I appreciate that!

comment:17 Changed 8 years ago by vbraun

  • Authors changed from Nicolas M. Thiéry to Volker Braun, Nicolas M. Thiéry
  • Description modified (diff)
  • Reviewers changed from Volker Braun? to Volker Braun
  • Summary changed from Fix warning in color option for 2D polyhedron to More plot options for polytopes

comment:18 Changed 8 years ago by vbraun

  • Description modified (diff)

comment:19 Changed 8 years ago by vbraun

For the patchbot:

Apply trac_14175_plot_options.patch

comment:20 Changed 8 years ago by nthiery

Hi Volker!

Yes, the user interface is much better as you did it! Thanks for the gift :-)

I ran some systematic tests and added them to the documentation/tests of plot. I stumbled on a couple corner cases, and reworked a bit the logic in plot. In particular, the default value for the colors is now handled by plot. A consequence is that the default coloring is uniform for all dimension, whereas we used to have:

  • 2D: blue wireframe, light green (0,1,0) fill
  • 3D: light green (0,1,0) fill, blue wireframe
  • 0D, 1D: everything blue

Is that ok?

The default is currently set to "green" for the fill and "blue" for the wireframe, but feel free to change it to your taste. I also did a couple micro improvements to the doc. If you are happy with the reviewer patch, feel free to fold it in, customize the default colors and set a positive review on my behalf (assuming I did not screw up and the patchbot remains green of course).

Cheers,

Nicolas

comment:21 Changed 8 years ago by nthiery

Oh, just one thing: since there maybe several points, lines, and even polygons (3D), should the options be named points, lines, polygones?

comment:22 follow-up: Changed 8 years ago by vbraun

  • Reviewers changed from Volker Braun to Volker Braun, Nicolas M. Thiéry
  • Status changed from needs_review to positive_review

There may be multiple points but only one point option setting, which is why I settled on the singular. Also, none of the other plot options are plural afaik. Since you apparently don't have a particular preference either I'd say we keep it in singular.

Positive review to the revewer patch...

comment:23 in reply to: ↑ 22 Changed 8 years ago by nthiery

Replying to vbraun:

There may be multiple points but only one point option setting, which is why I settled on the singular. Also, none of the other plot options are plural afaik. Since you apparently don't have a particular preference either I'd say we keep it in singular.

Ok!

Positive review to the revewer patch...

Great :-)

That might well be our first joint patch; it's been a pleasure!

And at the end of the day, I am actually going to use the point/line option to get a wireframe root system plot that my daughter can reproduce with her construction kit :-) So you were perfectly right it was to be done in full!

comment:24 Changed 8 years ago by jdemeyer

  • Milestone changed from sage-5.8 to sage-5.9

comment:25 follow-up: Changed 8 years ago by jdemeyer

  • Description modified (diff)

Are you sure the first patch is the one which should be applied?

Changed 8 years ago by nthiery

comment:26 in reply to: ↑ 25 Changed 8 years ago by nthiery

Replying to jdemeyer:

Are you sure the first patch is the one which should be applied?

Oops. Thanks for catching this. Since anyway the patch header had to be updated for the reviewer's patch, I folded together the two patches and reposted the result. Now it's correct :-)

comment:27 Changed 8 years ago by jdemeyer

  • Merged in set to sage-5.9.beta0
  • Resolution set to fixed
  • Status changed from positive_review to closed

comment:28 Changed 6 years ago by kcrisman

Question (likely dumb): could the behavior at this ask.sagemath question be related to this change (or #11634)? Thanks!

Note: See TracTickets for help on using tickets.