Skip to content

pyplot.plot conflict: markerfacecolor ='none' and alpha #11104

Closed

Description

@zsunpku

Bug report

Bug summary
I tried to use a previously-works-fine code to make a plot but failed to reproduce the same one -- after updating matplotlib to 2.2. The hollow circles in plot (defined by markerfacecolor='None') are now in black facecolor. After manually locating the error, I found that the keyword 'alpha' seems conflict to markerfacecolor = 'None' which never happened before. This conflict will only affect facecolor set as 'None'.

Code for reproduction

import matplotlib.pyplot as plt
# This works properly
plt.figure()
plt.plot([1,2,3],[1,2,3],'o',c='g',markeredgecolor='g',markersize = 10,markerfacecolor='r',linewidth=2,alpha=1)
plt.show()
# markerfacecolor='none' conflicts with alpha keyword
plt.figure()
plt.plot([1,2,3],[1,2,3],'o',c='g',markeredgecolor='g',markersize = 10,markerfacecolor='none',linewidth=2,alpha=1)
plt.show()
# markerfacecolor='none' conflicts with alpha keyword, and this happens on different alphas
plt.figure()
plt.plot([1,2,3],[1,2,3],'o',c='g',markeredgecolor='g',markersize = 10,markerfacecolor='none',linewidth=2,alpha=0.5)
plt.show()
# remove alpha keyword and markerfacecolor='none' works well
plt.figure()
plt.plot([1,2,3],[1,2,3],'o',c='g',markeredgecolor='g',markersize = 10,markerfacecolor='none',linewidth=2) # no alpha here
plt.show()

Actual outcome

![1](https://user-images.githubusercontent.com/13745875/39099965-ee512c2c-4650-11e8-9cc4-969ebe75ac2a.png)
![2](https://user-images.githubusercontent.com/13745875/39099966-ee604bb2-4650-11e8-9245-d846bbed9523.png)
![3](https://user-images.githubusercontent.com/13745875/39099968-ee6aa2f6-4650-11e8-8420-bde423460955.png)
![4](https://user-images.githubusercontent.com/13745875/39099969-ee73fbbc-4650-11e8-9358-72e00202e539.png)


Matplotlib version

  • Operating system: Windows 10 x64
  • Matplotlib version: 2.2
  • Matplotlib backend (print(matplotlib.get_backend())): both terminal ipython (Qt5Agg) and jupyter notebook (module://ipykernel.pylab.backend_inline)
  • Python version: 3.6.2
  • Jupyter version (if applicable): 4.3.0
  • Other libraries: N/A

matplotlib and python installed by conda

channel by default

Thanks a lot!

Activity

  1. ImportanceOfBeingErnest commented on Apr 22, 2018

    @ImportanceOfBeingErnest
    Member

    This is reproducible on current master. print(line.get_markerfacecolor()) prints "none" correctly, so this might happen at draw time?!

  2. anntzer commented on Apr 22, 2018

    @anntzer
    Contributor

    Bisects to #9911. Humpf...

  3. anntzer commented on Apr 22, 2018

    @anntzer
    Contributor

    After some investigation, turns out that the signature

        def draw_markers(self, gc, marker_path, marker_trans, path,
                         trans, rgbFace=None):
    

    indeed requires rgbFace to possibly be None. The face color is converted per

        if (!convert_face(faceobj, gc, &face)) {
            return NULL;
        }
    

    and convert_face explicitly checks for None at

    int convert_face(PyObject *color, GCAgg &gc, agg::rgba *rgba)
    {
        if (!convert_rgba(color, rgba)) {
            return 0;
        }
    
        if (color != NULL && color != Py_None) {  // <-- HERE.
            if (gc.forced_alpha || PySequence_Size(color) == 3) {
                rgba->a = gc.alpha;
            }
        }
    
        return 1;
    }
    

    Looks like the "easy" fix is to manually revert the relevant parts of #9911.

  4. anntzer commented on Apr 23, 2018

    @anntzer
    Contributor

    Actually I have a better fix coming.

  5. added this to the v2.2.3 milestone on Apr 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions