Changeset 644430f in sasmodels


Ignore:
Timestamp:
Dec 23, 2015 8:02:39 AM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
e3a9733
Parents:
cade620
Message:

fix plots. 1D: handle all NaN. 2D: handle arbitrary detector shape. both: add x,y labels

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/data.py

    r9404dd3 r644430f  
    275275 
    276276        #print(vmin, vmax) 
    277         positive = False 
     277        all_positive = True 
     278        some_present = False 
    278279        if plot_data: 
    279             mdata = masked_array(data.y, data.mask) 
     280            mdata = masked_array(data.y, data.mask.copy()) 
    280281            mdata[~np.isfinite(mdata)] = masked 
    281282            if view is 'log': 
    282283                mdata[mdata <= 0] = masked 
    283             plt.errorbar(data.x, scale*mdata, yerr=data.dy, fmt='.') 
    284             positive = positive or (mdata>0).any() 
     284            plt.errorbar(data.x/10, scale*mdata, yerr=data.dy, fmt='.') 
     285            all_positive = all_positive and (mdata>0).all() 
     286            some_present = some_present or (mdata.count() > 0) 
     287 
    285288 
    286289        if plot_theory: 
    287             mtheory = masked_array(theory, data.mask) 
     290            mtheory = masked_array(theory, data.mask.copy()) 
     291            mtheory[~np.isfinite(mtheory)] = masked 
    288292            if view is 'log': 
    289                 mtheory[mtheory<= 0] = masked 
    290             plt.plot(data.x, scale*mtheory, '-', hold=True) 
    291             positive = positive or (mtheory>0).any() 
    292  
    293         plt.xscale(view) 
    294         plt.yscale('linear' if view == 'q4' or not positive else view) 
    295         plt.xlabel('Q') 
    296         plt.ylabel('I(Q)') 
     293                mtheory[mtheory<=0] = masked 
     294            plt.plot(data.x/10, scale*mtheory, '-', hold=True) 
     295            all_positive = all_positive and (mtheory>0).all() 
     296            some_present = some_present or (mtheory.count() > 0) 
     297 
     298        plt.xscale('linear' if not some_present else view) 
     299        plt.yscale('linear' 
     300                   if view == 'q4' or not some_present or not all_positive 
     301                   else view) 
     302        plt.xlabel("$q$/nm$^{-1}$") 
     303        plt.ylabel('$I(q)$') 
    297304 
    298305    if plot_resid: 
     
    300307            plt.subplot(122) 
    301308 
    302         mresid = masked_array(resid, data.mask) 
    303         plt.plot(data.x, mresid, '-') 
     309        mresid = masked_array(resid, data.mask.copy()) 
     310        mresid[~np.isfinite(mresid)] = masked 
     311        some_present = (mresid.count() > 0) 
     312        plt.plot(data.x/10, mresid, '-') 
     313        plt.xlabel("$q$/nm$^{-1}$") 
    304314        plt.ylabel('residuals') 
    305         plt.xlabel('Q') 
    306         plt.xscale(view) 
     315        plt.xscale('linear' if not some_present else view) 
    307316 
    308317 
     
    366375        _plot_2d_signal(data, target, view=view, vmin=vmin, vmax=vmax) 
    367376        plt.title('data') 
    368         plt.colorbar() 
     377        h = plt.colorbar() 
     378        h.set_label('$I(q)$') 
    369379 
    370380    if plot_theory: 
     
    377387        _plot_2d_signal(data, theory, view=view, vmin=vmin, vmax=vmax) 
    378388        plt.title('theory') 
    379         plt.colorbar() 
     389        h = plt.colorbar() 
     390        h.set_label('$I(q)$') 
    380391 
    381392    #if plot_data or plot_theory: 
     
    388399            plt.subplot(122) 
    389400        _plot_2d_signal(data, resid, view='linear') 
    390         plt.colorbar() 
    391401        plt.title('residuals') 
     402        h = plt.colorbar() 
     403        h.set_label('$\Delta I(q)$') 
    392404 
    393405 
     
    414426    #plottable = Iq 
    415427    plottable = masked_array(image, ~valid | data.mask) 
    416     xmin, xmax = min(data.qx_data), max(data.qx_data) 
    417     ymin, ymax = min(data.qy_data), max(data.qy_data) 
     428    xmin, xmax = min(data.qx_data)/10, max(data.qx_data)/10 
     429    ymin, ymax = min(data.qy_data)/10, max(data.qy_data)/10 
    418430    # TODO: fix vmin, vmax so it is shared for theory/resid 
    419431    vmin = vmax = None 
     
    423435    except: 
    424436        vmin, vmax = 0, 1 
    425     plt.imshow(plottable.reshape(128, 128), 
     437    plt.imshow(plottable.reshape(len(data.xbins), len(data.ybins)), 
    426438               interpolation='nearest', aspect=1, origin='upper', 
    427439               extent=[xmin, xmax, ymin, ymax], vmin=vmin, vmax=vmax) 
     440    plt.xlabel("$q_x$/nm$^{-1}$") 
     441    plt.ylabel("$q_y$/nm$^{-1}$") 
    428442 
    429443 
Note: See TracChangeset for help on using the changeset viewer.