MatPlotLib : covering circle is transparent instead of opaque












0















I generate an SVG file with the library MatPlotLib.



I'm trying to get a circle with black edge and white face; the face has to be not transparent. I played with the parameters edgecolor, facecolor, alpha, fill but no combination gives me what I want. Axis and lines get not covered by the circle:



import os
import locale
import matplotlib.pyplot as plt
import matplotlib.lines as mlines

files =

# -----------------------------------------------------------------------------
class Fig:
def __init__(self, filename, figsize = [4,4]):
self.filename = filename
self.fig = plt.figure(figsize=figsize)
self.fig.gca().axis('off')

def save(self):
global files
files.append(self.filename)
self.fig.savefig(self.filename+'.svg')


# -----------------------------------------------------------------------------
class FigNotHomeo(Fig):
def __init__(self, filename, figsize = [4, 4]):
Fig.__init__(self, filename, figsize)
ax = self.fig.gca()
ax.set_xlim(-1.1,1.1)
ax.set_ylim(-1.05, 1.05)
ax.axis('on')
ax.spines['left'].set_position('center')
ax.spines['bottom'].set_position('center')
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks([-1,1])
ax.yaxis.set_ticks([-1,1])
ax.tick_params( axis='y', labeltop= True ) # does not work
x = [1,-1,1,0]
y = [1,-1,-1,0]
ax.add_line(mlines.Line2D(x,y, color='black'))
# facecolor='white', edgecolor = 'black', fill = True, alpha=1, clip_on=True
c = plt.Circle((0, 0), radius=0.03, facecolor='white', edgecolor = 'black', alpha=1, fill = True, clip_on=False)
ax.add_patch(c)

# -----------------------------------------------------------------------------
def main():
FigNotHomeo('NotHomeo', figsize=[6, 6]).save()

if __name__== "__main__":
main()









share|improve this question



























    0















    I generate an SVG file with the library MatPlotLib.



    I'm trying to get a circle with black edge and white face; the face has to be not transparent. I played with the parameters edgecolor, facecolor, alpha, fill but no combination gives me what I want. Axis and lines get not covered by the circle:



    import os
    import locale
    import matplotlib.pyplot as plt
    import matplotlib.lines as mlines

    files =

    # -----------------------------------------------------------------------------
    class Fig:
    def __init__(self, filename, figsize = [4,4]):
    self.filename = filename
    self.fig = plt.figure(figsize=figsize)
    self.fig.gca().axis('off')

    def save(self):
    global files
    files.append(self.filename)
    self.fig.savefig(self.filename+'.svg')


    # -----------------------------------------------------------------------------
    class FigNotHomeo(Fig):
    def __init__(self, filename, figsize = [4, 4]):
    Fig.__init__(self, filename, figsize)
    ax = self.fig.gca()
    ax.set_xlim(-1.1,1.1)
    ax.set_ylim(-1.05, 1.05)
    ax.axis('on')
    ax.spines['left'].set_position('center')
    ax.spines['bottom'].set_position('center')
    ax.spines['right'].set_color('none')
    ax.spines['top'].set_color('none')
    ax.xaxis.set_ticks([-1,1])
    ax.yaxis.set_ticks([-1,1])
    ax.tick_params( axis='y', labeltop= True ) # does not work
    x = [1,-1,1,0]
    y = [1,-1,-1,0]
    ax.add_line(mlines.Line2D(x,y, color='black'))
    # facecolor='white', edgecolor = 'black', fill = True, alpha=1, clip_on=True
    c = plt.Circle((0, 0), radius=0.03, facecolor='white', edgecolor = 'black', alpha=1, fill = True, clip_on=False)
    ax.add_patch(c)

    # -----------------------------------------------------------------------------
    def main():
    FigNotHomeo('NotHomeo', figsize=[6, 6]).save()

    if __name__== "__main__":
    main()









    share|improve this question

























      0












      0








      0








      I generate an SVG file with the library MatPlotLib.



      I'm trying to get a circle with black edge and white face; the face has to be not transparent. I played with the parameters edgecolor, facecolor, alpha, fill but no combination gives me what I want. Axis and lines get not covered by the circle:



      import os
      import locale
      import matplotlib.pyplot as plt
      import matplotlib.lines as mlines

      files =

      # -----------------------------------------------------------------------------
      class Fig:
      def __init__(self, filename, figsize = [4,4]):
      self.filename = filename
      self.fig = plt.figure(figsize=figsize)
      self.fig.gca().axis('off')

      def save(self):
      global files
      files.append(self.filename)
      self.fig.savefig(self.filename+'.svg')


      # -----------------------------------------------------------------------------
      class FigNotHomeo(Fig):
      def __init__(self, filename, figsize = [4, 4]):
      Fig.__init__(self, filename, figsize)
      ax = self.fig.gca()
      ax.set_xlim(-1.1,1.1)
      ax.set_ylim(-1.05, 1.05)
      ax.axis('on')
      ax.spines['left'].set_position('center')
      ax.spines['bottom'].set_position('center')
      ax.spines['right'].set_color('none')
      ax.spines['top'].set_color('none')
      ax.xaxis.set_ticks([-1,1])
      ax.yaxis.set_ticks([-1,1])
      ax.tick_params( axis='y', labeltop= True ) # does not work
      x = [1,-1,1,0]
      y = [1,-1,-1,0]
      ax.add_line(mlines.Line2D(x,y, color='black'))
      # facecolor='white', edgecolor = 'black', fill = True, alpha=1, clip_on=True
      c = plt.Circle((0, 0), radius=0.03, facecolor='white', edgecolor = 'black', alpha=1, fill = True, clip_on=False)
      ax.add_patch(c)

      # -----------------------------------------------------------------------------
      def main():
      FigNotHomeo('NotHomeo', figsize=[6, 6]).save()

      if __name__== "__main__":
      main()









      share|improve this question














      I generate an SVG file with the library MatPlotLib.



      I'm trying to get a circle with black edge and white face; the face has to be not transparent. I played with the parameters edgecolor, facecolor, alpha, fill but no combination gives me what I want. Axis and lines get not covered by the circle:



      import os
      import locale
      import matplotlib.pyplot as plt
      import matplotlib.lines as mlines

      files =

      # -----------------------------------------------------------------------------
      class Fig:
      def __init__(self, filename, figsize = [4,4]):
      self.filename = filename
      self.fig = plt.figure(figsize=figsize)
      self.fig.gca().axis('off')

      def save(self):
      global files
      files.append(self.filename)
      self.fig.savefig(self.filename+'.svg')


      # -----------------------------------------------------------------------------
      class FigNotHomeo(Fig):
      def __init__(self, filename, figsize = [4, 4]):
      Fig.__init__(self, filename, figsize)
      ax = self.fig.gca()
      ax.set_xlim(-1.1,1.1)
      ax.set_ylim(-1.05, 1.05)
      ax.axis('on')
      ax.spines['left'].set_position('center')
      ax.spines['bottom'].set_position('center')
      ax.spines['right'].set_color('none')
      ax.spines['top'].set_color('none')
      ax.xaxis.set_ticks([-1,1])
      ax.yaxis.set_ticks([-1,1])
      ax.tick_params( axis='y', labeltop= True ) # does not work
      x = [1,-1,1,0]
      y = [1,-1,-1,0]
      ax.add_line(mlines.Line2D(x,y, color='black'))
      # facecolor='white', edgecolor = 'black', fill = True, alpha=1, clip_on=True
      c = plt.Circle((0, 0), radius=0.03, facecolor='white', edgecolor = 'black', alpha=1, fill = True, clip_on=False)
      ax.add_patch(c)

      # -----------------------------------------------------------------------------
      def main():
      FigNotHomeo('NotHomeo', figsize=[6, 6]).save()

      if __name__== "__main__":
      main()






      matplotlib






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 24 '18 at 18:10









      PeptideChainPeptideChain

      24319




      24319
























          1 Answer
          1






          active

          oldest

          votes


















          2














          Patches generally have a lower zorder than lines.



          import matplotlib.pyplot as plt

          circle = plt.Circle((.5, .5), radius=0.2)
          plt.gca().add_patch(circle)

          line = plt.Line2D([0,1],[0,1], color='black')
          plt.gca().add_line(line)

          plt.show()


          enter image description here



          However, you may of course set the zorder to your desire.



          import matplotlib.pyplot as plt

          circle = plt.Circle((.5, .5), radius=0.2, zorder=3)
          plt.gca().add_patch(circle)

          line = plt.Line2D([0,1],[0,1], color='black', zorder=2)
          plt.gca().add_line(line)

          plt.show()


          enter image description here






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53461035%2fmatplotlib-covering-circle-is-transparent-instead-of-opaque%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            Patches generally have a lower zorder than lines.



            import matplotlib.pyplot as plt

            circle = plt.Circle((.5, .5), radius=0.2)
            plt.gca().add_patch(circle)

            line = plt.Line2D([0,1],[0,1], color='black')
            plt.gca().add_line(line)

            plt.show()


            enter image description here



            However, you may of course set the zorder to your desire.



            import matplotlib.pyplot as plt

            circle = plt.Circle((.5, .5), radius=0.2, zorder=3)
            plt.gca().add_patch(circle)

            line = plt.Line2D([0,1],[0,1], color='black', zorder=2)
            plt.gca().add_line(line)

            plt.show()


            enter image description here






            share|improve this answer




























              2














              Patches generally have a lower zorder than lines.



              import matplotlib.pyplot as plt

              circle = plt.Circle((.5, .5), radius=0.2)
              plt.gca().add_patch(circle)

              line = plt.Line2D([0,1],[0,1], color='black')
              plt.gca().add_line(line)

              plt.show()


              enter image description here



              However, you may of course set the zorder to your desire.



              import matplotlib.pyplot as plt

              circle = plt.Circle((.5, .5), radius=0.2, zorder=3)
              plt.gca().add_patch(circle)

              line = plt.Line2D([0,1],[0,1], color='black', zorder=2)
              plt.gca().add_line(line)

              plt.show()


              enter image description here






              share|improve this answer


























                2












                2








                2







                Patches generally have a lower zorder than lines.



                import matplotlib.pyplot as plt

                circle = plt.Circle((.5, .5), radius=0.2)
                plt.gca().add_patch(circle)

                line = plt.Line2D([0,1],[0,1], color='black')
                plt.gca().add_line(line)

                plt.show()


                enter image description here



                However, you may of course set the zorder to your desire.



                import matplotlib.pyplot as plt

                circle = plt.Circle((.5, .5), radius=0.2, zorder=3)
                plt.gca().add_patch(circle)

                line = plt.Line2D([0,1],[0,1], color='black', zorder=2)
                plt.gca().add_line(line)

                plt.show()


                enter image description here






                share|improve this answer













                Patches generally have a lower zorder than lines.



                import matplotlib.pyplot as plt

                circle = plt.Circle((.5, .5), radius=0.2)
                plt.gca().add_patch(circle)

                line = plt.Line2D([0,1],[0,1], color='black')
                plt.gca().add_line(line)

                plt.show()


                enter image description here



                However, you may of course set the zorder to your desire.



                import matplotlib.pyplot as plt

                circle = plt.Circle((.5, .5), radius=0.2, zorder=3)
                plt.gca().add_patch(circle)

                line = plt.Line2D([0,1],[0,1], color='black', zorder=2)
                plt.gca().add_line(line)

                plt.show()


                enter image description here







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 24 '18 at 18:42









                ImportanceOfBeingErnestImportanceOfBeingErnest

                134k13148224




                134k13148224
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53461035%2fmatplotlib-covering-circle-is-transparent-instead-of-opaque%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    404 Error Contact Form 7 ajax form submitting

                    How to know if a Active Directory user can login interactively

                    Refactoring coordinates for Minecraft Pi buildings written in Python