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.


    matplot to view

    Pythonista
    2
    3
    1319
    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.
    • donnieh
      donnieh last edited by

      I have a matplot view being output to the console. How would I adjust my code to output it to a new view instead?

      The first bit of code is how the plot is going to the console.

      The second is the view I want the plot to be in.

      plt.plot(x, y)
      	plt.title('Amplitude Vs Time')
      	plt.show()
      
      view = ui.View()
      	view.background_color = 'white'
      	view.present('sheet')
      
      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by

        Something like this should work:

        from matplotlib import pyplot as plt
        import ui
        
        plt.plot([1, 2, 4, 2])
        
        plt.savefig('plot.png')
        img_view = ui.ImageView()
        img_view.frame = (0, 0, 500, 500)
        img_view.content_mode = ui.CONTENT_SCALE_ASPECT_FIT
        img_view.image = ui.Image.named('plot.png')
        img_view.present('sheet')
        
        1 Reply Last reply Reply Quote 0
        • donnieh
          donnieh last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors