python - Can't get canvas to draw fig in matplotlib -
from basic understanding using matplotlib store desired plt in 'fig' , can draw said 'fig' using canvas.draw() operation. if case shouldn't have problems since do, going on , what's logic behind getting on canvas. also, end goal display plot within qtpy window. results far can window , canvas show canvas shows empty. have been looking @ http://matplotlib.sourceforge.net/users/artists.html , feel i'm doing isn't entirely wrong, perhaps i'm overlooking nuance. here code i'm referencing:
def drawthis(self): self.axes.clear() self.axes.grid(self.grid_cb.ischecked()) self.fig = plt.figure(figsize=(11,7),dpi=self.dpi) file = filelist[selfile] valid = [scolumn] matrix = np.loadtxt(file, skiprows=1, usecols=valid) colcount = np.loadtxt(file, dtype=object) totalcols = colcount.shape[1] kdedata = np.array(matrix) datarange = (decimal(max(abs(kdedata))) / 10).quantize(1, rounding=round_up) * 10 gkde = stats.gaussian_kde(kdedata) ind = np.linspace(-int(datarange), int(datarange), len(kdedata) * ssamples) kdepdf = gkde.evaluate(ind) ##plot histogram of sample plt.hist(kdedata, len(kdedata), normed=1, alpha=0.20) ##plot data generating density plt.plot(ind, stats.norm.pdf(ind), 'r', linewidth=0.8, label='dgp normal') ##plot estimated density plt.plot(ind, kdepdf, 'g', linewidth=0.8, label='kde') plt.title('kde '+ str(namelist[selfile])) plt.legend() self.fig.canvas.draw()
i don't have experience matplotlib, in looking @ code, wonder if use of pyplot
correct? way code looks me, using pyplot generate data (which dont keep return values of), , plot it, yet think not operating on axis instance.
an example of how have seen matplotlib being used can found here: segfault using matplotlib pyqt .. directly creating pyqt4 figurecanvas , plotting directly axis instance.
it seems pyplot.plot()
method can take figure , axis parameter tell instance use. wonder if not using axis, since can't see in example how create axis itself. take @ @ docs here
my guess might try doing this:
plt.plot(ind, kdepdf, 'g', axis=self.axis, linewidth=0.8, label='kde')
or, maybe confirm have createe self.axis
using self.axis = plt.axis()
, or try doing plotting directly axis instance?
Comments
Post a Comment