示例#1
0
    def test_draw_xy_plot(self):
        """draw_xy_plot() properly produces an output html file
        """
        out_file = os.path.join(self.dir_name, "test.html")
        argv = (
            "p.plot -x x -y btrace ctrace -s o- --xlabel myxlabel "
            "--ylabel myylabel --title mytitle --theme darkgrid "
            "--context talk --palette muted -a .5 --nogrid "
            "--legend best --xlim 0 10 --ylim -10 10 "
            "--savefig {}".format(out_file)
        ).split()
        with patch("pandashells.lib.plot_lib.sys.argv", argv):
            pl.clf()
            df = pd.DataFrame({"x": range(10), "btrace": [-x for x in range(10)], "ctrace": [x for x in range(10)]})
            parser = argparse.ArgumentParser()
            arg_lib.add_args(parser, "io_in", "xy_plotting", "decorating", "example")

            parser.add_argument("-a", "--alpha", help="Set opacity", nargs=1, default=[1.0], type=float)
            args = parser.parse_args()
            plot_lib.draw_xy_plot(args, df)
            with open(out_file) as f:
                html = f.read()
                self.assertTrue("myxlabel" in html)
                self.assertTrue("myylabel" in html)
                self.assertTrue("mytitle" in html)
                self.assertTrue("btrace" in html)
                self.assertTrue("ctrace" in html)
                self.assertTrue("1" in html)
                self.assertTrue("10" in html)
示例#2
0
def main():
    msg = textwrap.dedent("""
        Creates interactive xy plots.  Loosely based around matplotlib's
        pyplot.plot command.

        -----------------------------------------------------------------------
        Examples:

            * Really simple plot
                p.linspace 1 10 7 | p.plot -x c0 -y c0

            * Plot two traces
                p.linspace 0 6.28 100\\
                | p.df 'df["cos"]=np.cos(df.t)' 'df["sin"]=np.sin(df.t)'\\
                        --names t\\
                | p.plot -x t -y sin cos\\
                         --style '.-' 'o-' --alpha 1 .2 --legend best

            * Plot sea-level time series
                p.example_data -d sealevel\\
                | p.plot -x year -y sealevel_mm --style '.'\\
                --xlabel year --ylabel 'relative sea level (mm)'\\
                --title 'Sea Level Rise' --legend best --xlim 1995 2015
        -----------------------------------------------------------------------
        """)

    #  read command line arguments
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter, description=msg)

    arg_lib.add_args(parser, 'io_in', 'xy_plotting', 'decorating')

    parser.add_argument("-a",
                        "--alpha",
                        help="Set opacity level(s)",
                        nargs='+',
                        default=[1.],
                        type=float,
                        metavar='alpha')

    # parse arguments
    args = parser.parse_args()

    # get the input dataframe
    df = io_lib.df_from_input(args)

    # set the appropriate theme
    plot_lib.set_plot_styling(args)

    # draw the plot
    plot_lib.draw_xy_plot(args, df)
示例#3
0
def main():
    msg = textwrap.dedent(
        """
        Creates interactive xy plots.  Loosely based around matplotlib's
        pyplot.plot command.

        -----------------------------------------------------------------------
        Examples:

            * Really simple plot
                p.linspace 1 10 7 | p.plot -x c0 -y c0

            * Plot two traces
                p.linspace 0 6.28 100\\
                | p.df 'df["cos"]=np.cos(df.t)' 'df["sin"]=np.sin(df.t)'\\
                        --names t\\
                | p.plot -x t -y sin cos\\
                         --style '.-' 'o-' --alpha 1 .2 --legend best

            * Plot sea-level time series
                p.example_data -d sealevel\\
                | p.plot -x year -y sealevel_mm --style '.'\\
                --xlabel year --ylabel 'relative sea level (mm)'\\
                --title 'Sea Level Rise' --legend best --xlim 1995 2015
        -----------------------------------------------------------------------
        """
    )

    #  read command line arguments
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter, description=msg)

    arg_lib.add_args(parser, 'io_in', 'xy_plotting', 'decorating')

    parser.add_argument(
        "-a", "--alpha", help="Set opacity level(s)", nargs='+', default=[1.],
        type=float, metavar='alpha')

    # parse arguments
    args = parser.parse_args()

    # get the input dataframe
    df = io_lib.df_from_input(args)

    # set the appropriate theme
    plot_lib.set_plot_styling(args)

    # draw the plot
    plot_lib.draw_xy_plot(args, df)
示例#4
0
    def test_draw_xy_plot(self):
        """draw_xy_plot() properly produces an output html file
        """
        out_file = os.path.join(self.dir_name, 'test.html')
        argv = (
            'p.plot -x x -y btrace ctrace -s o- --xlabel myxlabel '
            '--ylabel myylabel --title mytitle --theme darkgrid '
            '--context talk --palette muted -a .5 --nogrid '
            '--legend best --xlim 0 10 --ylim -10 10 '
            '--savefig {}'.format(out_file)
        ).split()
        with patch('pandashells.lib.plot_lib.sys.argv', argv):
            pl.clf()
            df = pd.DataFrame(
                {
                    'x': range(10),
                    'btrace': [-x for x in range(10)],
                    'ctrace': [x for x in range(10)]
                })
            parser = argparse.ArgumentParser()
            arg_lib.add_args(
                parser, 'io_in', 'xy_plotting', 'decorating')

            parser.add_argument(
                "-a", "--alpha", help="Set opacity", nargs=1, default=[1.],
                type=float)
            args = parser.parse_args()
            plot_lib.draw_xy_plot(args, df)
            with open(out_file) as f:
                html = f.read()
                self.assertTrue('myxlabel' in html)
                self.assertTrue('myylabel' in html)
                self.assertTrue('mytitle' in html)
                self.assertTrue('btrace' in html)
                self.assertTrue('ctrace' in html)
                self.assertTrue('1' in html)
                self.assertTrue('10' in html)
示例#5
0
    def test_draw_xy_plot(self):
        """draw_xy_plot() properly produces an output html file
        """
        out_file = os.path.join(self.dir_name, 'test.html')
        argv = (
            'p.plot -x x -y btrace ctrace -s o- --xlabel myxlabel '
            '--ylabel myylabel --title mytitle --theme darkgrid '
            '--context talk --palette muted -a .5 --nogrid '
            '--legend best --xlim 0 10 --ylim -10 10 '
            '--savefig {}'.format(out_file)
        ).split()
        with patch('pandashells.lib.plot_lib.sys.argv', argv):
            pl.clf()
            df = pd.DataFrame(
                {
                    'x': range(10),
                    'btrace': [-x for x in range(10)],
                    'ctrace': [x for x in range(10)]
                })
            parser = argparse.ArgumentParser()
            arg_lib.add_args(
                parser, 'io_in', 'xy_plotting', 'decorating', 'example')

            parser.add_argument(
                "-a", "--alpha", help="Set opacity", nargs=1, default=[1.],
                type=float)
            args = parser.parse_args()
            plot_lib.draw_xy_plot(args, df)
            with open(out_file) as f:
                html = f.read()
                self.assertTrue('myxlabel' in html)
                self.assertTrue('myylabel' in html)
                self.assertTrue('mytitle' in html)
                self.assertTrue('btrace' in html)
                self.assertTrue('ctrace' in html)
                self.assertTrue('1' in html)
                self.assertTrue('10' in html)