Python matplotlib.pyplot.subplot2grid() Examples

The following are 30 code examples of matplotlib.pyplot.subplot2grid(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module matplotlib.pyplot , or try the search function .
Example #1
Source File: matplotlib_trading_chart.py    From tensortrade with Apache License 2.0 7 votes vote down vote up
def __init__(self, df):
        self.df = df

        # Create a figure on screen and set the title
        self.fig = plt.figure()

        # Create top subplot for net worth axis
        self.net_worth_ax = plt.subplot2grid((6, 1), (0, 0), rowspan=2, colspan=1)

        # Create bottom subplot for shared price/volume axis
        self.price_ax = plt.subplot2grid((6, 1), (2, 0), rowspan=8,
                                         colspan=1, sharex=self.net_worth_ax)

        # Create a new axis for volume which shares its x-axis with price
        self.volume_ax = self.price_ax.twinx()

        # Add padding to make graph easier to view
        plt.subplots_adjust(left=0.11, bottom=0.24, right=0.90, top=0.90, wspace=0.2, hspace=0)

        # Show the graph without blocking the rest of the program
        plt.show(block=False) 
Example #2
Source File: machFX10.py    From Pattern-Recognition-for-Forex-Trading with MIT License 6 votes vote down vote up
def graphRawFX():
    
    fig=plt.figure(figsize=(10,7))
    ax1 = plt.subplot2grid((40,40), (0,0), rowspan=40, colspan=40)
    ax1.plot(date,bid)
    ax1.plot(date,ask)
    ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S'))
    plt.grid(True)
    for label in ax1.xaxis.get_ticklabels():
            label.set_rotation(45)
    plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
    ax1_2 = ax1.twinx()
    ax1_2.fill_between(date, 0, (ask-bid), facecolor='g',alpha=.3)

    plt.subplots_adjust(bottom=.23)
    plt.show() 
Example #3
Source File: trellis_plots.py    From gmpe-smtk with GNU Affero General Public License v3.0 6 votes vote down vote up
def plot(self):
        """
        Create plot!
        """
        nrow = len(self.magnitudes)
        # Get means and standard deviations
        gmvs = self.get_ground_motion_values()
        fig = plt.figure(figsize=self.figure_size)
        fig.set_tight_layout({"pad":0.5})
        for rowloc in range(nrow):
            for colloc in range(self.nsites):
                self._build_plot(
                    plt.subplot2grid((nrow, self.nsites), (rowloc, colloc)), 
                    gmvs,
                    rowloc,
                    colloc)
        # Add legend
        lgd = plt.legend(self.lines,
                         self.labels,
                         loc=3.,
                         bbox_to_anchor=(1.1, 0.0),
                         fontsize=self.legend_fontsize)

        _save_image_tight(fig, lgd, self.filename, self.filetype, self.dpi)
        plt.show() 
Example #4
Source File: basenji_sat_plot2.py    From basenji with Apache License 2.0 6 votes vote down vote up
def setup_plot(figure_width, plot_len):
  spp = subplot_params(plot_len)

  plt.figure(figsize=(figure_width, 6))

  axes_list = []
  axes_list.append(plt.subplot2grid(
      (4, spp['heat_cols']), (0, spp['logo_start']),
      colspan=spp['logo_span']))
  axes_list.append(plt.subplot2grid(
      (4, spp['heat_cols']), (1, 0), colspan=spp['heat_cols']))
  axes_list.append(plt.subplot2grid(
      (4, spp['heat_cols']), (2, spp['logo_start']),
      colspan=spp['logo_span']))
  axes_list.append(plt.subplot2grid(
      (4, spp['heat_cols']), (3, 0), colspan=spp['heat_cols']))

  return axes_list 
Example #5
Source File: sequential_minimum_optimization.py    From Python with MIT License 6 votes vote down vote up
def test_demonstration():
    # change stdout
    print("\nStart plot,please wait!!!")
    sys.stdout = open(os.devnull, "w")

    ax1 = plt.subplot2grid((2, 2), (0, 0))
    ax2 = plt.subplot2grid((2, 2), (0, 1))
    ax3 = plt.subplot2grid((2, 2), (1, 0))
    ax4 = plt.subplot2grid((2, 2), (1, 1))
    ax1.set_title("linear svm,cost:0.1")
    test_linear_kernel(ax1, cost=0.1)
    ax2.set_title("linear svm,cost:500")
    test_linear_kernel(ax2, cost=500)
    ax3.set_title("rbf kernel svm,cost:0.1")
    test_rbf_kernel(ax3, cost=0.1)
    ax4.set_title("rbf kernel svm,cost:500")
    test_rbf_kernel(ax4, cost=500)

    sys.stdout = sys.__stdout__
    print("Plot done!!!") 
Example #6
Source File: test_tightlayout.py    From neural-network-animation with MIT License 6 votes vote down vote up
def test_tight_layout4():
    'Test tight_layout for subplot2grid'

    fig = plt.figure()

    ax1 = plt.subplot2grid((3, 3), (0, 0))
    ax2 = plt.subplot2grid((3, 3), (0, 1), colspan=2)
    ax3 = plt.subplot2grid((3, 3), (1, 0), colspan=2, rowspan=2)
    ax4 = plt.subplot2grid((3, 3), (1, 2), rowspan=2)

    example_plot(ax1)
    example_plot(ax2)
    example_plot(ax3)
    example_plot(ax4)

    plt.tight_layout() 
Example #7
Source File: test_tightlayout.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_tight_layout4():
    'Test tight_layout for subplot2grid'

    fig = plt.figure()

    ax1 = plt.subplot2grid((3, 3), (0, 0))
    ax2 = plt.subplot2grid((3, 3), (0, 1), colspan=2)
    ax3 = plt.subplot2grid((3, 3), (1, 0), colspan=2, rowspan=2)
    ax4 = plt.subplot2grid((3, 3), (1, 2), rowspan=2)

    example_plot(ax1)
    example_plot(ax2)
    example_plot(ax3)
    example_plot(ax4)

    plt.tight_layout() 
Example #8
Source File: dvs.py    From everest with MIT License 6 votes vote down vote up
def __init__(self):
        '''

        '''

        self.fig = pl.figure(figsize=(8.5, 11))
        self.fig.subplots_adjust(
            left=0.025 * (11 / 8.5), right=1 - 0.025 * (11 / 8.5),
            top=0.975, bottom=0.025)

        def GetFrame(y, x, dx, dy):
            return Frame(self.fig, pl.subplot2grid((160, 160), (y, x),
                         colspan=dx, rowspan=dy))
        self.title_left = GetFrame(0, 6, 44, 10)
        self.title_center = GetFrame(0, 50, 66, 10)
        self.title_right = GetFrame(0, 116, 44, 10)
        self._body = [GetFrame(12, 6, 148, 42),
                      GetFrame(62, 6, 148, 42),
                      GetFrame(112, 6, 148, 42)]
        for ax in self.fig.get_axes():
            ax.axis('off')
        self.bcount = 0 
Example #9
Source File: machFX7.py    From Pattern-Recognition-for-Forex-Trading with MIT License 6 votes vote down vote up
def graphRawFX():
    
    fig=plt.figure(figsize=(10,7))
    ax1 = plt.subplot2grid((40,40), (0,0), rowspan=40, colspan=40)
    ax1.plot(date,bid)
    ax1.plot(date,ask)
    
    #ax1.plot(date,((bid+ask)/2))
    #ax1.plot(date,percentChange(ask[0],ask),'r')
    ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S'))
    #####
    plt.grid(True)
    for label in ax1.xaxis.get_ticklabels():
            label.set_rotation(45)
    plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
    #######
    ax1_2 = ax1.twinx()
    #ax1_2.plot(date, (ask-bid))
    ax1_2.fill_between(date, 0, (ask-bid), facecolor='g',alpha=.3)
    #ax1_2.set_ylim(0, 3*ask.max())
    #######
    plt.subplots_adjust(bottom=.23)
    #plt.grid(True)
    plt.show() 
Example #10
Source File: machFX2.py    From Pattern-Recognition-for-Forex-Trading with MIT License 6 votes vote down vote up
def graphRawFX():
    date,bid,ask = np.loadtxt('GBPUSD1d.txt', unpack=True,
                              delimiter=',',
                              converters={0:mdates.strpdate2num('%Y%m%d%H%M%S')})

    fig=plt.figure(figsize=(10,7))

    ax1 = plt.subplot2grid((40,40), (0,0), rowspan=40, colspan=40)
    ax1.plot(date,bid)
    ax1.plot(date,ask)

    ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S'))

    for label in ax1.xaxis.get_ticklabels():
            label.set_rotation(45)
    plt.subplots_adjust(bottom=.23)
    plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
    plt.grid(True)
    plt.show() 
Example #11
Source File: machFX14.py    From Pattern-Recognition-for-Forex-Trading with MIT License 6 votes vote down vote up
def graphRawFX():
    
    fig=plt.figure(figsize=(10,7))
    ax1 = plt.subplot2grid((40,40), (0,0), rowspan=40, colspan=40)
    ax1.plot(date,bid)
    ax1.plot(date,ask)
    ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S'))
    plt.grid(True)
    for label in ax1.xaxis.get_ticklabels():
            label.set_rotation(45)
    plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
    ax1_2 = ax1.twinx()
    ax1_2.fill_between(date, 0, (ask-bid), facecolor='g',alpha=.3)

    plt.subplots_adjust(bottom=.23)
    plt.show() 
Example #12
Source File: machFX8.py    From Pattern-Recognition-for-Forex-Trading with MIT License 6 votes vote down vote up
def graphRawFX():
    
    fig=plt.figure(figsize=(10,7))
    ax1 = plt.subplot2grid((40,40), (0,0), rowspan=40, colspan=40)
    ax1.plot(date,bid)
    ax1.plot(date,ask)
    
    #ax1.plot(date,((bid+ask)/2))
    #ax1.plot(date,percentChange(ask[0],ask),'r')
    ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S'))
    #####
    plt.grid(True)
    for label in ax1.xaxis.get_ticklabels():
            label.set_rotation(45)
    plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
    #######
    ax1_2 = ax1.twinx()
    #ax1_2.plot(date, (ask-bid))
    ax1_2.fill_between(date, 0, (ask-bid), facecolor='g',alpha=.3)
    #ax1_2.set_ylim(0, 3*ask.max())
    #######
    plt.subplots_adjust(bottom=.23)
    #plt.grid(True)
    plt.show() 
Example #13
Source File: machFX16.py    From Pattern-Recognition-for-Forex-Trading with MIT License 6 votes vote down vote up
def graphRawFX():
    
    fig=plt.figure(figsize=(10,7))
    ax1 = plt.subplot2grid((40,40), (0,0), rowspan=40, colspan=40)
    ax1.plot(date,bid)
    ax1.plot(date,ask)
    ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S'))
    plt.grid(True)
    for label in ax1.xaxis.get_ticklabels():
            label.set_rotation(45)
    plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
    ax1_2 = ax1.twinx()
    ax1_2.fill_between(date, 0, (ask-bid), facecolor='g',alpha=.3)

    plt.subplots_adjust(bottom=.23)
    plt.show() 
Example #14
Source File: TradingChart.py    From RLTrader with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, df):
        self.df = df

        # Create a figure on screen and set the title
        self.fig = plt.figure()

        # Create top subplot for net worth axis
        self.net_worth_ax = plt.subplot2grid((6, 1), (0, 0), rowspan=2, colspan=1)

        # Create bottom subplot for shared price/volume axis
        self.price_ax = plt.subplot2grid((6, 1), (2, 0), rowspan=8, colspan=1, sharex=self.net_worth_ax)

        # Create a new axis for volume which shares its x-axis with price
        self.volume_ax = self.price_ax.twinx()

        # Add padding to make graph easier to view
        plt.subplots_adjust(left=0.11, bottom=0.24, right=0.90, top=0.90, wspace=0.2, hspace=0)

        # Show the graph without blocking the rest of the program
        plt.show(block=False) 
Example #15
Source File: machFX9.py    From Pattern-Recognition-for-Forex-Trading with MIT License 6 votes vote down vote up
def graphRawFX():
    
    fig=plt.figure(figsize=(10,7))
    ax1 = plt.subplot2grid((40,40), (0,0), rowspan=40, colspan=40)
    ax1.plot(date,bid)
    ax1.plot(date,ask)
    ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S'))
    plt.grid(True)
    for label in ax1.xaxis.get_ticklabels():
            label.set_rotation(45)
    plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
    ax1_2 = ax1.twinx()
    ax1_2.fill_between(date, 0, (ask-bid), facecolor='g',alpha=.3)

    plt.subplots_adjust(bottom=.23)
    plt.show() 
Example #16
Source File: machFX11.py    From Pattern-Recognition-for-Forex-Trading with MIT License 6 votes vote down vote up
def graphRawFX():
    
    fig=plt.figure(figsize=(10,7))
    ax1 = plt.subplot2grid((40,40), (0,0), rowspan=40, colspan=40)
    ax1.plot(date,bid)
    ax1.plot(date,ask)
    ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S'))
    plt.grid(True)
    for label in ax1.xaxis.get_ticklabels():
            label.set_rotation(45)
    plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
    ax1_2 = ax1.twinx()
    ax1_2.fill_between(date, 0, (ask-bid), facecolor='g',alpha=.3)

    plt.subplots_adjust(bottom=.23)
    plt.show() 
Example #17
Source File: machFX15.py    From Pattern-Recognition-for-Forex-Trading with MIT License 6 votes vote down vote up
def graphRawFX():
    
    fig=plt.figure(figsize=(10,7))
    ax1 = plt.subplot2grid((40,40), (0,0), rowspan=40, colspan=40)
    ax1.plot(date,bid)
    ax1.plot(date,ask)
    ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S'))
    plt.grid(True)
    for label in ax1.xaxis.get_ticklabels():
            label.set_rotation(45)
    plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
    ax1_2 = ax1.twinx()
    ax1_2.fill_between(date, 0, (ask-bid), facecolor='g',alpha=.3)

    plt.subplots_adjust(bottom=.23)
    plt.show() 
Example #18
Source File: machFX12.py    From Pattern-Recognition-for-Forex-Trading with MIT License 6 votes vote down vote up
def graphRawFX():
    
    fig=plt.figure(figsize=(10,7))
    ax1 = plt.subplot2grid((40,40), (0,0), rowspan=40, colspan=40)
    ax1.plot(date,bid)
    ax1.plot(date,ask)
    ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S'))
    plt.grid(True)
    for label in ax1.xaxis.get_ticklabels():
            label.set_rotation(45)
    plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
    ax1_2 = ax1.twinx()
    ax1_2.fill_between(date, 0, (ask-bid), facecolor='g',alpha=.3)

    plt.subplots_adjust(bottom=.23)
    plt.show() 
Example #19
Source File: images.py    From pyLAR with Apache License 2.0 6 votes vote down vote up
def showSlice(dataMatrix, title, color, subplotRow, referenceImName, slice_nr=-1):
    """Display a 2D slice within a given figure."""
    try:
        import matplotlib.pyplot as plt
    except ImportError:
        print "ShowSlice not supported - matplotlib not available"
        return
    im_ref = sitk.ReadImage(referenceImName)
    im_ref_array = sitk.GetArrayFromImage(im_ref)  # get numpy array
    z_dim, x_dim, y_dim = im_ref_array.shape  # get 3D volume shape
    if slice_nr == -1:
        slice_nr = z_dim / 2
    num_of_data = dataMatrix.shape[1]
    for i in range(num_of_data):
        plt.subplot2grid((3, num_of_data), (subplotRow, i))
        im = np.array(dataMatrix[:, i]).reshape(z_dim, x_dim, y_dim)
        implot = plt.imshow(np.fliplr(np.flipud(im[slice_nr, :, :])), color)
        plt.axis('off')
        plt.title(title + ' ' + str(i))
        # plt.colorbar()
    del im_ref, im_ref_array
    return 
Example #20
Source File: test_tightlayout.py    From ImageFusion with MIT License 6 votes vote down vote up
def test_tight_layout4():
    'Test tight_layout for subplot2grid'

    fig = plt.figure()

    ax1 = plt.subplot2grid((3, 3), (0, 0))
    ax2 = plt.subplot2grid((3, 3), (0, 1), colspan=2)
    ax3 = plt.subplot2grid((3, 3), (1, 0), colspan=2, rowspan=2)
    ax4 = plt.subplot2grid((3, 3), (1, 2), rowspan=2)

    example_plot(ax1)
    example_plot(ax2)
    example_plot(ax3)
    example_plot(ax4)

    plt.tight_layout() 
Example #21
Source File: scalar_monitor.py    From tfnn with MIT License 6 votes vote down vote up
def __init__(self, grid_space, objects, evaluator, figsize, sleep=0.001):
        super(ScaleMonitor, self).__init__(evaluator, 'score_monitor')
        self._network = self.evaluator.network
        self._axes = {}
        self._tplot_axes = {}
        self._vplot_axes = {}
        self._fig = plt.figure(figsize=figsize)
        self._sleep = sleep
        for r_loc, name in enumerate(objects):
            r_span, c_span = 1, grid_space[1]
            self._axes[name] = plt.subplot2grid(grid_space, (r_loc, 0), colspan=c_span, rowspan=r_span)
            if name != objects[-1]:
                plt.setp(self._axes[name].get_xticklabels(), visible=False)
            self._axes[name].set_ylabel(r'$%s$' % name.replace(' ', r'\ ').capitalize())
        self._fig.subplots_adjust(hspace=0.1)
        plt.ion()
        plt.show() 
Example #22
Source File: voyagerimb.py    From voyagerimb with MIT License 6 votes vote down vote up
def view_init(self):
        self.frame = tk.LabelFrame(self.browser.workframe, text=" Image ")
        self.frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=True, padx=7, pady=7)
        self.figure = plt.figure(figsize=(8, 12), dpi=70)
        self.ax1 = plt.subplot2grid((50,40), (0, 0), rowspan=40, colspan=40)
        self.ax2 = plt.subplot2grid((50,40), (42, 0), rowspan=8, colspan=40, sharex=self.ax1)
        plt.subplots_adjust(left=0.1, bottom=0.05, right=0.95, top=0.97, wspace=0.2, hspace=0.2)
        self.view_plot_image()
        self.canvas = FigureCanvasTkAgg(self.figure, self.frame)

        if self.mpltlib3:
            self.canvas.draw()
            toolbar = NavigationToolbar2Tk(self.canvas, self.frame).update()
        else:
            self.canvas.show()
            toolbar = NavigationToolbar2TkAgg(self.canvas, self.frame).update()

        self.canvas.get_tk_widget().pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True)

        self.canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, padx=2, pady=2, expand=True)
        self.frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=True, padx=7, pady=7) 
Example #23
Source File: StockTradingGraph.py    From Stock-Trading-Visualization with MIT License 6 votes vote down vote up
def __init__(self, df, title=None):
        self.df = df
        self.net_worths = np.zeros(len(df['Date']))

        # Create a figure on screen and set the title
        fig = plt.figure()
        fig.suptitle(title)

        # Create top subplot for net worth axis
        self.net_worth_ax = plt.subplot2grid(
            (6, 1), (0, 0), rowspan=2, colspan=1)

        # Create bottom subplot for shared price/volume axis
        self.price_ax = plt.subplot2grid(
            (6, 1), (2, 0), rowspan=8, colspan=1, sharex=self.net_worth_ax)

        # Create a new axis for volume which shares its x-axis with price
        self.volume_ax = self.price_ax.twinx()

        # Add padding to make graph easier to view
        plt.subplots_adjust(left=0.11, bottom=0.24,
                            right=0.90, top=0.90, wspace=0.2, hspace=0)

        # Show the graph without blocking the rest of the program
        plt.show(block=False) 
Example #24
Source File: winston_lutz.py    From pylinac with MIT License 6 votes vote down vote up
def plot_summary(self, show: bool=True):
        """Plot a summary figure showing the gantry sag and wobble plots of the three axes."""
        plt.figure(figsize=(11, 9))
        grid = (3, 6)
        gantry_sag_ax = plt.subplot2grid(grid, (0, 0), colspan=3)
        self._plot_deviation(GANTRY, gantry_sag_ax, show=False)
        epid_sag_ax = plt.subplot2grid(grid, (0, 3), colspan=3)
        self._plot_deviation(EPID, epid_sag_ax, show=False)
        if self._get_images((COLLIMATOR, REFERENCE))[0] > 1:
            coll_sag_ax = plt.subplot2grid(grid, (1, 0), colspan=3)
            self._plot_deviation(COLLIMATOR, coll_sag_ax, show=False)
        if self._get_images((COUCH, REFERENCE))[0] > 1:
            couch_sag_ax = plt.subplot2grid(grid, (1, 3), colspan=3)
            self._plot_deviation(COUCH, couch_sag_ax, show=False)

        for axis, axnum in zip((GANTRY, COLLIMATOR, COUCH), (0, 2, 4)):
            if self._get_images((axis, REFERENCE))[0] > 1:
                ax = plt.subplot2grid(grid, (2, axnum), colspan=2)
                self.plot_axis_images(axis=axis, ax=ax, show=False)
        if show:
            plt.tight_layout()
            plt.show() 
Example #25
Source File: test_tightlayout.py    From coffeegrindsize with MIT License 6 votes vote down vote up
def test_tight_layout4():
    'Test tight_layout for subplot2grid'

    fig = plt.figure()

    ax1 = plt.subplot2grid((3, 3), (0, 0))
    ax2 = plt.subplot2grid((3, 3), (0, 1), colspan=2)
    ax3 = plt.subplot2grid((3, 3), (1, 0), colspan=2, rowspan=2)
    ax4 = plt.subplot2grid((3, 3), (1, 2), rowspan=2)

    example_plot(ax1)
    example_plot(ax2)
    example_plot(ax3)
    example_plot(ax4)

    plt.tight_layout() 
Example #26
Source File: test_tightlayout.py    From twitter-stock-recommendation with MIT License 6 votes vote down vote up
def test_tight_layout4():
    'Test tight_layout for subplot2grid'

    fig = plt.figure()

    ax1 = plt.subplot2grid((3, 3), (0, 0))
    ax2 = plt.subplot2grid((3, 3), (0, 1), colspan=2)
    ax3 = plt.subplot2grid((3, 3), (1, 0), colspan=2, rowspan=2)
    ax4 = plt.subplot2grid((3, 3), (1, 2), rowspan=2)

    example_plot(ax1)
    example_plot(ax2)
    example_plot(ax3)
    example_plot(ax4)

    plt.tight_layout() 
Example #27
Source File: mpl_finance_ext.py    From Stock-Price-Prediction-With-Indicators with MIT License 6 votes vote down vote up
def _head(kwargs, data=None):
    # Prepare data ------------------------------------------
    if data is not None:
        for col in list(data):
            data[col] = pd.to_numeric(
                data[col], errors='coerce')

    # Build ax ----------------------------------------------
    fig = kwargs.get('fig', None)
    if fig is None:
        fig, _ = plt.subplots(facecolor=background_color)

    ax = kwargs.get('axis', None)
    if ax is None:
        ax = plt.subplot2grid(
            (4, 4), (0, 0),
            rowspan=4, colspan=4,
            facecolor=background_color
        )
    return fig, ax 
Example #28
Source File: get_face_enhancement_v1.py    From MobileFace with MIT License 5 votes vote down vote up
def main():
    args = parse_args() 
    enhance_tool = MobileFaceEnhance()
    img_list = os.listdir(args.image_dir)
    for img_name in img_list:
        im_path = os.path.join(args.image_dir, img_name)
        img = cv2.imread(im_path)
        gamma, hist = enhance_tool.hist_statistic(img, 
                                                  dark_th = args.dark_th, 
                                                  bright_th = args.bright_th, 
                                                  dark_shift = args.dark_shift, 
                                                  bright_shift = args.bright_shift)
        img_gamma = enhance_tool.gamma_trans(img, gamma)
        if not os.path.exists(args.result_dir):
            os.makedirs(args.result_dir)
        rst_path = os.path.join(args.result_dir, 'rst_debug' + img_name)
        cv2.imwrite(rst_path, img_gamma)

        img_stack = np.hstack((img, img_gamma))

        plt.figure(figsize=(5, 5))
        ax1 = plt.subplot2grid((2,1),(0, 0))
        ax1.set_title('Grayscale Histogram')
        ax1.set_xlabel("Bins")
        ax1.set_ylabel("Num of Pixels")
        ax1.plot(hist)
        ax1.set_xlim([0, 256])

        ax1 = plt.subplot2grid((2, 1), (1, 0), colspan=3, rowspan=1)
        ax1.set_title('Enhance Comparison')
        ax1.imshow(img_stack[:,:,::-1])

        plt.tight_layout()
        plt.show() 
Example #29
Source File: dvs.py    From everest with MIT License 5 votes vote down vote up
def __init__(self):
        '''

        '''

        self.fig = pl.figure(figsize=(8.5, 11))
        self.fig.subplots_adjust(
            left=0.025 * (11 / 8.5), right=1 - 0.025 * (11 / 8.5),
            top=0.975, bottom=0.025, hspace=0.5, wspace=0.5)
        def GetFrame(y, x, dx, dy):
            return Frame(self.fig, pl.subplot2grid((160, 160), (y, x),
                         colspan=dx, rowspan=dy))
        self.title_left = GetFrame(0, 6, 44, 10)
        self.title_center = GetFrame(0, 50, 66, 10)
        self.title_right = GetFrame(0, 116, 44, 10)
        for ax in self.fig.get_axes():
            ax.axis('off')
        kw = dict(colspan=40, rowspan=10)
        kwh = dict(colspan=10, rowspan=10)
        self.axes1 = [pl.subplot2grid((70, 60), (5, 5), **kw),
                      pl.subplot2grid((70, 60), (26, 5), **kw),
                      pl.subplot2grid((70, 60), (47, 5), **kw)]
        self.axes1h = [pl.subplot2grid((70, 60), (5, 45), **kwh),
                       pl.subplot2grid((70, 60), (26, 45), **kwh),
                       pl.subplot2grid((70, 60), (47, 45), **kwh)]
        self.axes2 = [pl.subplot2grid((70, 60), (15, 5), **kw),
                      pl.subplot2grid((70, 60), (36, 5), **kw),
                      pl.subplot2grid((70, 60), (57, 5), **kw)]
        self.axes2h = [pl.subplot2grid((70, 60), (15, 45), **kwh),
                       pl.subplot2grid((70, 60), (36, 45), **kwh),
                       pl.subplot2grid((70, 60), (57, 45), **kwh)]
        for ax in [self.axes1, self.axes1h, self.axes2, self.axes2h]:
            for axis in ax:
                axis.tick_params(direction='in') 
Example #30
Source File: ct.py    From pylinac with MIT License 5 votes vote down vote up
def plot_analyzed_image(self, show=True):
        """Plot the images used in the calculate and summary data.

        Parameters
        ----------
        show : bool
            Whether to plot the image or not.
        """
        def plot(ctp_module, axis):
            axis.imshow(ctp_module.image.array, cmap=get_dicom_cmap())
            ctp_module.plot_rois(axis)
            axis.autoscale(tight=True)
            axis.set_title(ctp_module.common_name)
            axis.axis('off')

        # set up grid and axes
        grid_size = (2, 4)
        hu_ax = plt.subplot2grid(grid_size, (0, 1))
        plot(self.ctp404, hu_ax)
        hu_lin_ax = plt.subplot2grid(grid_size, (0, 2))
        self.ctp404.plot_linearity(hu_lin_ax)
        if self._has_module(CTP486):
            unif_ax = plt.subplot2grid(grid_size, (0, 0))
            plot(self.ctp486, unif_ax)
            unif_prof_ax = plt.subplot2grid(grid_size, (1, 2), colspan=2)
            self.ctp486.plot_profiles(unif_prof_ax)
        if self._has_module(CTP528CP504):
            sr_ax = plt.subplot2grid(grid_size, (1, 0))
            plot(self.ctp528, sr_ax)
            mtf_ax = plt.subplot2grid(grid_size, (0, 3))
            self.ctp528.plot_mtf(mtf_ax)
        if self._has_module(CTP515):
            locon_ax = plt.subplot2grid(grid_size, (1, 1))
            plot(self.ctp515, locon_ax)

        # finish up
        plt.tight_layout()
        if show:
            plt.show()