new_axisline = par2._grid_helper.new_fixed_axis
    par2.axis["right2"] = new_axisline(loc="right",
                                       axes=par2,
                                       offset=offset)


    fig.add_axes(host)

    host.set_xlim(0, 2)
    host.set_ylim(0, 2)

    host.set_xlabel("Distance")
    host.set_ylabel("Density")
    par1.set_ylabel("Temperature")

    p1, = host.plot([0, 1, 2], [0, 1, 2], label="Density")
    p2, = par1.plot([0, 1, 2], [0, 3, 2], label="Temperature")
    p3, = par2.plot([0, 1, 2], [50, 30, 15], label="Velocity")

    par1.set_ylim(0, 4)
    par2.set_ylim(1, 65)

    host.legend()

    host.axis["left"].label.set_color(p1.get_color())
    par1.axis["right"].label.set_color(p2.get_color())
    par2.axis["right2"].label.set_color(p3.get_color())

    plt.draw()
    plt.show()
Beispiel #2
0
    par2.set_ylabel("Velocity")
    offset = (60, 0)
    new_axisline = par2._grid_helper.new_fixed_axis
    par2.axis["right2"] = new_axisline(loc="right", axes=par2, offset=offset)

    fig.add_axes(host)

    host.set_xlim(0, 2)
    host.set_ylim(0, 2)

    host.set_xlabel("Distance")
    host.set_ylabel("Density")
    par1.set_ylabel("Temperature")

    p1, = host.plot([0, 1, 2], [0, 1, 2], label="Density")
    p2, = par1.plot([0, 1, 2], [0, 3, 2], label="Temperature")
    p3, = par2.plot([0, 1, 2], [50, 30, 15], label="Velocity")

    par1.set_ylim(0, 4)
    par2.set_ylim(1, 65)

    host.legend()

    host.axis["left"].label.set_color(p1.get_color())
    par1.axis["right"].label.set_color(p2.get_color())
    par2.axis["right2"].label.set_color(p3.get_color())

    plt.draw()
    plt.show()
Beispiel #3
0
def runner (parser, options, args):
    
    options = Options (options)

    run_method = getattr(parser, 'run_method', 'subcommand')
    if os.name=='posix' and run_method == 'subprocess':
        print 'This script cannot be run using subprocess method. Choose subcommand to continue.'
        return

    if args:
        if len (args)==1:
            if options.input_path:
                print >> sys.stderr, "WARNING: overwriting input path %r with %r" % (options.input_path,  args[0])
            options.input_path = args[0]

    if options.input_path is None:
        parser.error('Expected --input-path but got nothing')

    data, titles = RowFile (options.input_path).read(with_titles = True)
    if options.print_keys:
        print 'rowfile keys:' + ', '.join(data.keys())
        print 'length:', len(data[data.keys()[0]] or [])
        return

    if not options.x_keys and not options.y_keys:
        options.x_keys = titles[0]
        options.y_keys = ','.join(titles[1:])
        parser.save_options(options, [])

    if not options.x_keys or not options.y_keys:
        print 'No x or y keys specified for the plot.'
        return

    x_keys = [str (k).strip() for k in options.x_keys.split (',')]
    y_keys = [str (k).strip() for k in options.y_keys.split (',')]

    from mpl_toolkits.axes_grid.parasite_axes import HostAxes, ParasiteAxes
    import matplotlib.pyplot as plt
    fig = plt.figure(1, figsize=(12,6))
    host = HostAxes(fig, [0.1, 0.1, 0.55, 0.8])
    host.axis["right"].set_visible(False)
    fig.add_axes(host)

    host.set_title(options.input_path)

    legend_list = []
    axes_ylim = []
    plot_axes = []

    for x_key in x_keys:
        x_data = data.get(x_key)
        if x_data is None:
            print 'Rowfile does not contain a column named %r' % (x_key)
            continue
        offset = 20
        host.set_xlabel(x_key)
        for y_key in y_keys:
            plot_str = 'plot'
            if y_key.startswith('log:'):
                y_key = y_key[4:]
                plot_str = 'semilogy'
            y_data = data.get(y_key)
            if y_data is None:
                print 'Rowfile does not contain a column named %r' % (y_key)
                continue
            if axes_ylim:
                ax = ParasiteAxes(host, sharex=host)
                host.parasites.append(ax)
                #ax.axis["right"].set_visible(True)
                #ax.axis["right"].major_ticklabels.set_visible(True)
                #ax.axis["right"].label.set_visible(True)
                new_axisline = ax._grid_helper.new_fixed_axis
                ax_line = ax.axis["right2"] = new_axisline(loc="right",
                                                  axes=ax,
                                                  offset=(offset,0))
                if plot_str=='semilogy':
                    offset += 60
                else:
                    offset += 40
            else:
                ax = host
                ax_line = ax.axis['left']
            ax.set_ylabel(y_key)
            p, = getattr(ax, plot_str)(x_data, y_data, label = y_key)
            axes_ylim.append((ax, min (y_data), max (y_data)))
            plot_axes.append((p, ax_line))
    [ax.set_ylim(mn,mx) for ax,mn,mx in axes_ylim]
    #[ax_line.label.set_color (p.get_color()) for p, ax in plot_axes]
    host.legend()

    def on_keypressed(event):
        key = event.key
        if key=='q':
            sys.exit(0)

    fig.canvas.mpl_connect('key_press_event', on_keypressed)

    plt.draw()

    output_path = options.get (output_path='')
    if output_path:
        plt.savefig (output_path)
        print 'wrote',output_path
        sys.exit(0)
    plt.show()