omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Another Matplotlib problem

    Pythonista
    2
    2
    2628
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ihf
      ihf last edited by

      (I don't know why my previous posting resulted in 2 empty posts which I cannot delete)

      Here is another simple example that either crashes Pythonista or gives an error (undoubtedly due to my coding):

      import matplotlib.pyplot as plt
      
      # Pie chart, where the slices will be ordered and plotted counter-clockwise:
      labels = ['a', 'b', 'c']
      sizes = [.3, .4, .2], 
      explode = (0, 0, 0, 0)  # only "explode" the 2nd slice (i.e. 'Hogs')
      
      fig1, ax1 = plt.subplots()
      ax1.bar(height=sizes, labels=labels, autopct='%1.1f%%',
             shadow=True, startangle=90)
      ax1.axis('equal')  # Equal aspect ratio ensures that pie is drawn as a circle.
      
      plt.show()```
      
      This crashes 2.7 and gives this traceback for 3.5:
      
      Traceback (most recent call last):
       File "/private/var/mobile/Containers/Shared/AppGroup/4F06F35D-865B-4115-B827-BA053B3731EF/Pythonista3/Documents/matplotlib-piechart-example.py", line 10, in <module>
         shadow=True, startangle=90)
      TypeError: bar() missing 1 required positional argument: 'left'
      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @ihf last edited by cvp

        @ihf some different errors:

        • a , at end of sizes
        • bar instead of pie
        • missing explode parameter
        • explode length not ok
        import matplotlib.pyplot as plt
        
        # Pie chart, where the slices will be ordered and plotted counter-clockwise:
        labels = ['a', 'b', 'c']
        sizes = [.3, .4, .2]
        explode = [0, 0, 0 ]  # only "explode" the 2nd slice (i.e. 'Hogs')
        
        fig1, ax1 = plt.subplots()
        ax1.pie(sizes, labels=labels, autopct='%1.1f%%',
               shadow=True, startangle=90,explode=explode)
        ax1.axis('equal')  # Equal aspect ratio ensures that pie is drawn as a circle.
        
        plt.show()
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        Powered by NodeBB Forums | Contributors