python - plotting with matplotlib from a module -


it's first time i'm using python plot , guess don't quite understand interactions between objects in matplotlib. i'm having following module:

import numpy np import matplotlib.pyplot plt  def plotsomething(x,y):     fig = plt.figure()     ax = fig.add_subplot(111)     ax.set_xscale("log", nonposx='clip')     ax.set_yscale("log", nonposy='clip')     ax.scatter(x,y)                                  #(1)     plt.scatter(x,y)                                 #(2) 

and plots fine when function called (given x , y).

a) if comment out (1) or (2) axis' plotted not scatter itself.

b) however, if both (1) , (2) uncommented , add vars s=5, marker='+' either (1) xor (2) the figure show both markers (one on top of other) - default 'o' , '+', meaning plot scatter twice.

but - if having both (1) , (2) uncommented i'm plotting twice, why need have both (1) , (2) in order see scatter? why in case (a) no scatter plot @ all?

i'm puzzled. can guide me through?

what happening related python's garbage collection. can't tell going on because provided code sample never renders plot. i'm guessing rendering outside function, in case, doing del fig before rendering (drawing).

this should work:

def plotsomething(x,y):     fig = plt.figure()     ax = fig.add_subplot(111)     ax.set_xscale("log", nonposx='clip')     ax.set_yscale("log", nonposy='clip')     ax.scatter(x,y)        fig.savefig('test.png') 

if want delay render/draw pass reference:

def plotsomething(x,y):     fig = plt.figure()     ax = fig.add_subplot(111)     ax.set_xscale("log", nonposx='clip')     ax.set_yscale("log", nonposy='clip')     ax.scatter(x,y)        return fig 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -