Skip to content

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

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

Closed
zsunpku opened this issue Apr 22, 2018 · 4 comments · Fixed by #11105
Closed

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

zsunpku opened this issue Apr 22, 2018 · 4 comments · Fixed by #11105

Comments

@zsunpku
Copy link

zsunpku commented Apr 22, 2018

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!

@ImportanceOfBeingErnest
Copy link
Member

ImportanceOfBeingErnest commented Apr 22, 2018

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

@anntzer
Copy link
Contributor

anntzer commented Apr 22, 2018

Bisects to #9911. Humpf...

@anntzer
Copy link
Contributor

anntzer commented Apr 22, 2018

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.

@anntzer
Copy link
Contributor

anntzer commented Apr 23, 2018

Actually I have a better fix coming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants