Esempio n. 1
0
def scatter_and_line():
    """Example containing both a scatter and line graph"""

    # Make random data points around straight line
    random_linear = np.zeros((1000, 2))
    random_linear[:, 0] = np.random.uniform(0, 10, 1000)
    random_error = np.random.normal(0.0, 2.0, 1000)
    random_linear[:, 1] = random_linear[:, 0] * 2.0 + 1.0 + random_error

    # Make datasets, order determining line graph on top
    dataset_a = DataSet(random_linear, plot='scatter', order=0, label='Random')
    dataset_b = DataSet(linear,
                        plot='line',
                        colour='black',
                        order=1,
                        label='Linear')

    # Colour scatter graph by error
    dataset_a.set_colour(map='coolwarm', colour=random_error)

    # Make plot object and add datasets
    plot = Plot()
    plot.set_text(latex=True)
    plot.add_dataset(dataset_a)
    plot.add_dataset(dataset_b)
    plot.set_legend(legend=True)

    # Plot graph and display
    plot.plot()
    plot.save(name='./figures/2d_scatter_and_line', fmt='png')
    plot.display()
Esempio n. 2
0
def simple_surface():
    """Example of surface plot, using either mesh or points"""

    # Make dataset with data provided as [x,y,z], where x,y,z, are meshes
    dataset_a = DataSet([mesh_x, mesh_y, func_1],
                        plot='surface_mesh',
                        colour_map='Blues')

    # Make plot and add data
    plot = Plot(dim=3, elevation=20, angle=130)
    plot.add_dataset(dataset_a)

    # Plot graph and display
    plot.plot()
    plot.set_axes(xlim=(-1.05, 1.05), ylim=(-2.05, 2.05), zlim=(-0.55, 0.55))
    plot.display()

    # Make dataset with data provided as (n,3)
    dataset_b = DataSet(random_3d_b, plot='surface_points', colour_map='Reds')

    # Make plot and add data
    plot = Plot(dim=3, elevation=20, angle=130)
    plot.add_dataset(dataset_a)

    # Plot graph and display
    plot.plot()
    # plot.set_axes(xlim=(-1.05,1.05),ylim=(-2.05,2.05),zlim=(-0.55,0.55))
    plot.display()
Esempio n. 3
0
def advanced_contour():
    """Example contour plot of function z(x,y)"""

    # Make two datasets, with same data provided [x,y,z], to highlight different contours
    dataset_a = DataSet([x_mesh, y_mesh, z],
                        plot='contour',
                        colour_map='coolwarm',
                        colour_norm=(-0.5, 0.5),
                        line_width=1,
                        line_style='--')
    dataset_a.set_contours(number=9,
                           limits=(-1, 1))  # Set number of contours and limits
    dataset_b = DataSet([x_mesh, y_mesh, z],
                        plot='contour',
                        colour_map='Greys',
                        colour_norm=(-1, 0),
                        line_width=0.5,
                        line_style='-')
    dataset_b.set_contours(levels=[0.0])  # Set specific contour values

    # Make plot and add data
    plot = Plot()
    plot.add_dataset(dataset_a)
    plot.add_dataset(dataset_b)
    plot.set_axes(xlim=(-4, 4), ylim=(-4, 4))

    # Plot graph and display
    plot.plot()
    plot.save(name='./figures/2d_contour', fmt='png')
    plot.display()
Esempio n. 4
0
def simple_scatter():
    """Example of two overlaid scatter plots"""

    # Make two datasets specifying scatter graph
    dataset_a = DataSet(random_2d_a, plot='scatter')
    dataset_b = DataSet(random_2d_b, plot='scatter')

    # Make plot object and add data sets
    plot = Plot()
    plot.add_dataset(dataset_a)
    plot.add_dataset(dataset_b)

    # Plot graph and display
    plot.plot()
    plot.save(name='./figures/2d_simple_scatter', fmt='png')
    plot.display()
Esempio n. 5
0
def simple_line():
    """Example of two overlaid line graphs"""

    # Make two datasets
    dataset_a = DataSet(sine)
    dataset_b = DataSet(cosine)

    # Make plot and add data
    plot = Plot()
    plot.set_text()
    plot.add_dataset(dataset_a)
    plot.add_dataset(dataset_b)

    # Plot graph and display
    plot.plot()
    plot.save(name='./figures/2d_simple_line', fmt='png')
    plot.display()
Esempio n. 6
0
def advanced_line():
    """Example of line graphs demonstrating options"""

    # Make dataset specifying arguments
    dataset_a = DataSet(sine,
                        line_style='-',
                        line_width=1.5,
                        marker_style='o',
                        marker_size='4')

    # Make dataset changing options using setters
    dataset_b = DataSet(cosine)
    dataset_b.set_line(style='--', width=1.5)
    dataset_b.set_colour(colour='royalblue')

    # Make plot object and adjust properties using setters
    plot = Plot()
    plot.set_text(latex=True, label=12)
    plot.add_dataset(dataset_a)
    plot.add_dataset(dataset_b)
    plot.set_axes(xlim=(0, 8),
                  ylim=(-1.1, 1.1),
                  xlabel=r'$x$',
                  ylabel=r'$f\left(x\right)$',
                  xticks=(1.0, 0.2),
                  yticks=(0.2, 0.05))

    # Plot graph and display
    plot.plot()
    plot.save(name='./figures/2d_advanced_line', fmt='png')
    plot.display()
Esempio n. 7
0
def simple_bar():
    """Example of simple bar chart"""

    # Make random discrete data
    discrete_a = np.zeros((8, 2))
    discrete_b = np.zeros((8, 2))
    discrete_c = np.zeros((8, 2))
    discrete_a[:, 0] = np.arange(8)
    discrete_b[:, 0] = np.arange(8)
    discrete_c[:, 0] = np.arange(8)
    discrete_a[:, 1] = np.random.rand(8) * 10
    discrete_b[:, 1] = np.random.rand(8) * 10
    discrete_c[:, 1] = np.random.rand(8) * 10

    # Make data sets, if using multiple bar_width must be the same
    dataset_a = DataSet(discrete_a,
                        colour='pink',
                        bar_width=0.8,
                        plot='bar',
                        label='A')
    dataset_b = DataSet(discrete_b,
                        colour='violet',
                        bar_width=0.8,
                        plot='bar',
                        label='B')
    dataset_c = DataSet(discrete_c,
                        colour='darkviolet',
                        bar_width=0.8,
                        plot='bar',
                        label='C')

    # Make plot object and add data sets
    plot = Plot()
    plot.add_dataset(dataset_a)
    plot.add_dataset(dataset_b)
    plot.add_dataset(dataset_c)
    plot.set_axes(xticks=(1, 1), xlim=(-0.5, 7.5), ylim=(0, 12))
    plot.set_legend(legend=True, location='upper right')
    plot.set_text(legend=8)

    # Plot graph and display
    plot.plot()
    plot.save(name='./figures/2d_simple_bar', fmt='png')
    plot.display()
Esempio n. 8
0
def simple_scatter():
    """Example of two overlaid scatter plots"""

    # Make two datasets specifying scatter graph, first coloured by random points, second sized by random points
    dataset_a = DataSet(random_3d_a,
                        plot='scatter',
                        colour_map='Reds',
                        colour=random_1d_a)
    dataset_b = DataSet(random_3d_b,
                        plot='scatter',
                        colour='blue',
                        marker_size=random_1d_b * 10)

    # Make plot object, set as 3d and add data sets
    plot = Plot()
    plot.set_dimensions(dim=3)
    plot.add_dataset(dataset_a)
    plot.add_dataset(dataset_b)

    # Plot graph and display
    plot.plot()
    plot.display()
Esempio n. 9
0
def simple_heat():
    """Example heatmap of function z=z(x,y)"""

    # Make dataset, with data provided [x,y,z]
    dataset_a = DataSet([x_mesh, y_mesh, z], plot='heat')

    # Make plot and add data
    plot = Plot()
    plot.set_axes(xlim=(-2, 2), ylim=(-2, 2))
    plot.add_dataset(dataset_a)

    # Plot graph and display
    plot.plot()
    plot.display()
Esempio n. 10
0
def simple_contour():
    """Example contour plot of function z(x,y)"""

    # Make dataset, with data provided [x,y,z]
    dataset_a = DataSet([x_mesh, y_mesh, z],
                        plot='contour',
                        colour_map='Greys')

    # Make plot and add data
    plot = Plot()
    plot.add_dataset(dataset_a)

    # Plot graph and display
    plot.plot()
    plot.display()
Esempio n. 11
0
def simple_line():
    """Example of parametric line graph"""

    # Make datasets
    dataset_a = DataSet(heart, plot='line')

    # Make plot and add data
    plot = Plot(dim=3, elevation=115, angle=-90)
    plot.set_axes(xlim=(-20, 20),
                  ylim=(-20, 20),
                  zlim=(-5, 35),
                  xticks=(10, 10),
                  yticks=())
    plot.add_dataset(dataset_a)

    # Plot graph and display
    plot.plot()
    plot.display()
Esempio n. 12
0
def advanced_heat():
    """Example heatmap of function z=z(x,y) with additional options"""

    # Make dataset, with data provided [x,y,z], colour normalisation conditions and interpolation method
    dataset_a = DataSet([x_mesh, y_mesh, z],
                        plot='heat',
                        colour_map='Blues',
                        colour_norm=(-1, 1),
                        surface_interpolation='bilinear')

    # Make plot and add data
    plot = Plot()
    plot.add_dataset(dataset_a)
    plot.set_axes(xlim=(-4, 4), ylim=(-4, 4))

    # Plot graph and display
    plot.plot()
    plot.save(name='./figures/2d_heat', fmt='png')
    plot.display()
Esempio n. 13
0
def error():
    """Example of a simple line graph with error bars, or line graph with shading"""

    # Make data set using errors
    dataset_a = DataSet(oscillating,
                        error_y=oscillating_error,
                        plot='error_bar',
                        label='Data and error')
    dataset_a.set_error(interval=5, width=1, cap=2)
    dataset_b = DataSet(oscillating,
                        plot='error_shade',
                        error_y=oscillating_error,
                        order=0,
                        colour='lightgrey',
                        label='Error')
    dataset_c = DataSet(oscillating,
                        plot='line',
                        order=1,
                        colour='firebrick',
                        label='Data')

    # Make line graph with error bars
    plot_bar = Plot()
    plot_bar.set_legend(legend=True)
    plot_bar.add_dataset(dataset_a)
    plot_bar.plot()
    plot_bar.save(name='./figures/2d_error_bar', fmt='png')
    plot_bar.display()

    # Make line graph with shaded errors
    plot_shade = Plot()
    plot_shade.set_legend(legend=True, location='upper left')
    plot_shade.add_dataset(dataset_b)
    plot_shade.add_dataset(dataset_c)
    plot_shade.plot()
    plot_shade.save(name='./figures/2d_error_shade', fmt='png')
    plot_shade.display()
Esempio n. 14
0
# Generate data
cosine = np.zeros((100, 2))
cosine[:, 0] = np.linspace(0, 10, 100)
cosine[:, 1] = np.cos(cosine[:, 0])

random = np.zeros((50, 2))
random[:, 0] = np.random.uniform(0, 10, 50)
random[:, 1] = np.random.uniform(-1, 1, 50)
random_size = np.random.uniform(5, 50, 50)
random_colour = np.random.uniform(0, 1, 50)

# Make DataSet specifying properties on instantiation
dataset_a = DataSet(cosine,
                    plot='line',
                    label='cosine',
                    colour='black',
                    line_width=2)

# Make DataSet specifiying properties through setters
dataset_b = DataSet(random, plot='scatter', label='random')
dataset_b.set_marker(style='o', size=random_size)
dataset_b.set_colour(map='coolwarm', colour=random_colour)

# Make Plot class and add DataSets
plot = Plot()
plot.add_dataset(dataset_a)
plot.add_dataset(dataset_b)

# Adjust plot properties
plot.set_axes(xlim=(0, 10),