Changeset 3983


Ignore:
Timestamp:
May 19, 2019 10:39:46 AM (5 years ago)
Author:
toby
Message:

add contour to set limits w/Apply button; finish contour U/D implementation for Cmin

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIplot.py

    r3982 r3983  
    18891889        elif event.key == 'o' and not G2frame.SinglePlot:
    18901890            G2frame.Cmax = 1.0
     1891            G2frame.Cmin = 0.0
    18911892            Page.plotStyle['Offset'] = [0,0]
    18921893        elif event.key == 'c' and 'PWDR' in plottype:
     
    18951896                G2frame.SinglePlot = False
    18961897                Page.plotStyle['Offset'] = [0.,0.]
     1898                G2frame.FixedLimits['cylims'] = ['','']  # reset manual limits
    18971899            else:
    18981900                G2frame.SinglePlot = True               
     
    25282530                dbox[i].SetValue(dbox[i].GetValue())
    25292531            dbox[i].Enable(checked)
     2532        def applyLims(event):
     2533            Page.toolbar.push_current()
     2534            CurLims = {}
     2535            CurLims['xlims'] = list(Plot.get_xlim())
     2536            if G2frame.Weight:
     2537                CurLims['ylims'] = list(Page.figure.axes[1].get_ylim())
     2538                CurLims['dylims'] = list(Page.figure.axes[2].get_ylim())
     2539            elif G2frame.Contour:
     2540                CurLims['ylims'] = list(Plot.get_ylim())
     2541                CurLims['cylims'] = list(Page.Img.get_clim())
     2542            else:
     2543                CurLims['ylims'] = list(Plot.get_ylim())
     2544                CurLims['dylims'] = [0,0]
     2545            for var in 'xlims','ylims','dylims','cylims':
     2546                for i in range(2):
     2547                    if not G2frame.UseLimits[var][i]: continue
     2548                    try:
     2549                        CurLims[var][i] = float(G2frame.FixedLimits[var][i])
     2550                        CurLims[var][i] = float(G2frame.FixedLimits[var][i])
     2551                    except:
     2552                        pass
     2553            Plot.set_xlim(CurLims['xlims'])
     2554            if G2frame.Weight:
     2555                Page.figure.axes[1].set_ylim(CurLims['ylims'])
     2556                Page.figure.axes[2].set_ylim(CurLims['dylims'])
     2557            elif G2frame.Contour:
     2558                Plot.set_ylim(CurLims['ylims'])
     2559                Page.Img.set_clim(CurLims['cylims'])
     2560            else:
     2561                Plot.set_ylim(CurLims['ylims'])
     2562            Page.toolbar.push_current()
     2563            Plot.figure.canvas.draw()
     2564       
     2565        # onSetPlotLim starts here
    25302566        dlg = wx.Dialog(G2frame.plotFrame,
    25312567                    style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
     
    25452581        if G2frame.Weight:
    25462582            lblkeys += [('(obs-calc)/sig ','dylims')]
     2583        elif G2frame.Contour:
     2584            lblkeys += [('contour','cylims')]
     2585
    25472586        for lbl,key in lblkeys:
    25482587            gsizer.Add(wx.StaticText(dlg,wx.ID_ANY,lbl),0,wx.ALL)
     
    25582597        vbox.Add((10,10),1,wx.ALL|wx.EXPAND,1)
    25592598        hbox = wx.BoxSizer(wx.HORIZONTAL)
     2599        hbox.Add((-1,-1),1,wx.ALL|wx.EXPAND,1)
     2600        #btn = wx.Button(dlg, wx.ID_CLOSE)
     2601        #btn.Bind(wx.EVT_BUTTON,lambda event:dlg.EndModal(wx.ID_CANCEL))
     2602        #hbox.Add(btn)
     2603        btn = wx.Button(dlg, wx.ID_ANY, label='Apply')
     2604        btn.Bind(wx.EVT_BUTTON,applyLims)
     2605        hbox.Add(btn)
    25602606        OKbtn = wx.Button(dlg, wx.ID_OK)
    25612607        OKbtn.Bind(wx.EVT_BUTTON,lambda event:dlg.EndModal(wx.ID_OK))
    2562         hbox.Add((-1,-1),1,wx.ALL|wx.EXPAND,1)
    25632608        hbox.Add(OKbtn)
    25642609        hbox.Add((-1,-1),1,wx.ALL|wx.EXPAND,1)
     
    25682613        dlg.ShowModal()
    25692614        dlg.Destroy()
    2570         # apply values
    2571         Page.toolbar.push_current()
    2572         CurLims = {}
    2573         CurLims['xlims'] = list(Plot.get_xlim())
    2574         if G2frame.Weight:
    2575             CurLims['ylims'] = list(Page.figure.axes[1].get_ylim())
    2576             CurLims['dylims'] = list(Page.figure.axes[2].get_ylim())
    2577         else:
    2578             CurLims['ylims'] = list(Plot.get_ylim())
    2579             CurLims['dylims'] = [0,0]
    2580         for var in 'xlims','ylims','dylims':
    2581             for i in range(2):
    2582                 if not G2frame.UseLimits[var][i]: continue
    2583                 try:
    2584                     CurLims[var][i] = float(G2frame.FixedLimits[var][i])
    2585                 except:
    2586                     pass
    2587         Plot.set_xlim(CurLims['xlims'])
    2588         if G2frame.Weight:
    2589             Page.figure.axes[1].set_ylim(CurLims['ylims'])
    2590             Page.figure.axes[2].set_ylim(CurLims['dylims'])
    2591         else:
    2592             Plot.set_ylim(CurLims['ylims'])
    2593         Page.toolbar.push_current()
    2594         Plot.figure.canvas.draw()
     2615        applyLims(None) # apply limits
    25952616        #GSASIIpath.IPyBreak()
    25962617       
     
    26902711        G2frame.FixedLimits
    26912712    except:
    2692         G2frame.FixedLimits = {'xlims':['',''],'ylims':['',''],
    2693                                        'dylims':['','']}
     2713        G2frame.FixedLimits = {i:['',''] for i in ('xlims','ylims','dylims','cylims')}
    26942714    try:
    26952715        G2frame.UseLimits
    26962716    except:
    2697         G2frame.UseLimits = {'xlims':[False,False],'ylims':[False,False],
    2698                                        'dylims':[False,False]}
     2717        G2frame.UseLimits = {i:[False,False] for i in ('xlims','ylims','dylims','cylims')}
    26992718    #=====================================================================================
    27002719    # code to setup for plotting Rietveld results. Turns off multiplot,
     
    27242743            G2frame.ErrorBars = True
    27252744        newPlot = True
     2745        G2frame.Cmin = 0.0
    27262746        G2frame.Cmax = 1.0
    27272747#        Page.canvas.mpl_connect('key_press_event', OnPlotKeyPress)
     
    27682788    DifLine = ['']
    27692789    if G2frame.Contour:
    2770         Page.Choice = (' key press','d: lower contour max','u: raise contour max','o: reset contour max','g: toggle grid',
     2790        Page.Choice = (' key press',
     2791            'd: lower contour max','u: raise contour max',
     2792            'D: lower contour min','U: raise contour min',
     2793            'o: reset contour limits','g: toggle grid',
    27712794            'i: interpolation method','S: color scheme','c: contour off','t: temperature for y-axis','s: toggle sqrt plot')
    27722795    else:
     
    33133336        time0 = time.time()
    33143337        acolor = mpl.cm.get_cmap(G2frame.ContourColor)
    3315         Img = Plot.imshow(ContourZ,cmap=acolor,vmin=0,vmax=Ymax*G2frame.Cmax,interpolation=G2frame.Interpolate,
     3338        Page.Img = Plot.imshow(ContourZ,cmap=acolor,
     3339                    vmin=Ymax*G2frame.Cmin,vmax=Ymax*G2frame.Cmax,
     3340                    interpolation=G2frame.Interpolate,
    33163341            extent=[ContourX[0],ContourX[-1],ContourY[0],ContourY[-1]],aspect='auto',origin='lower')
    33173342        if G2frame.TforYaxis:
    3318             imgAx = Img.axes
     3343            imgAx = Page.Img.axes
    33193344            ytics = imgAx.get_yticks()
    33203345            ylabs = [Temps[int(i)] for i in ytics[:-1]]
    33213346            imgAx.set_yticklabels(ylabs)
    3322         Page.figure.colorbar(Img)
     3347        Page.figure.colorbar(Page.Img)
    33233348        if timeDebug:
    33243349            print('Contour display time: %.3f'%(time.time()-time0))
     
    46234648    if G2frame.Contour and len(PlotList)>1:
    46244649        acolor = mpl.cm.get_cmap(G2frame.ContourColor)
    4625         Img = Plot.imshow(ContourZ,cmap=acolor,vmin=Ymax*G2frame.Cmin,vmax=Ymax*G2frame.Cmax,interpolation=G2frame.Interpolate,
     4650        Img = Plot.imshow(ContourZ,cmap=acolor,
     4651                    vmin=Ymax*G2frame.Cmin,vmax=Ymax*G2frame.Cmax,
     4652                    interpolation=G2frame.Interpolate,
    46264653            extent=[ContourX[0],ContourX[-1],ContourY[0],ContourY[-1]],aspect='auto',origin='lower')
    46274654        Page.figure.colorbar(Img)
Note: See TracChangeset for help on using the changeset viewer.