Esempio n. 1
0
def plot_expression(equation):
    y = []
    expressions = [equation.replace('x', str(i)) for i in range(600)]
    for expression in expressions:
        calc = Calculator(expression)
        y.append(calc.calculate())
    plot(y, title="Simple X-Y Graph")
Esempio n. 2
0
def test_multi_series_plotting():
    ys = [
        [math.sin(i / (10 + i / 50)) - math.sin(i / 100) for i in range(1000)],
        # Make sure we also support plotting series of different length
        [math.sin(i / (10 + i / 50)) - math.sin(i / 100) - 1 for i in range(800)],
    ]
    plot(ys, title="Double sine wave", color=True)
Esempio n. 3
0
 def set_uni(self, data, time):
     y = data
     yo = time
     uni.plot([y, yo],
              lines=1,
              x_gridlines=[10, 20, 30],
              y_gridlines=[0, 2, 4, 6, 8, 10])
Esempio n. 4
0
def test_plotting_one_million_points():
    nr_samples = 1_000_000
    acceptable_time_in_seconds = 0.3

    ys = np.random.normal(0, 1, nr_samples)

    start_time = time.time()
    plot(ys)
    assert time.time() - start_time < acceptable_time_in_seconds
Esempio n. 5
0
import pandas as pd
import numpy as np
import sys

argv = list(sys.argv)

from IPython.terminal.embed import InteractiveShellEmbed
my_shell = InteractiveShellEmbed()
result = my_shell.getoutput("pip install uniplot")
print(result)
result = my_shell.getoutput("cat output.log | grep %s | awk '{print $NF}'" % (argv[1]))

from uniplot import plot
result = list(map(float, result))
result = pd.DataFrame({0:result}).ewm(alpha=float(argv[2])).mean().fillna(0.0)[0].clip(0.0, 1e9)
plot(result)
Esempio n. 6
0
def plot_beliefs(
    sensors: List[Sensor],
    start: datetime,
    duration: timedelta,
    belief_time_before: Optional[datetime],
    source: Optional[DataSource],
):
    """
    Show a simple plot of belief data directly in the terminal.
    """
    sensors = list(sensors)
    min_resolution = min([s.event_resolution for s in sensors])

    # query data
    beliefs_by_sensor = TimedBelief.search(
        sensors=sensors,
        event_starts_after=start,
        event_ends_before=start + duration,
        beliefs_before=belief_time_before,
        source=source,
        one_deterministic_belief_per_event=True,
        resolution=min_resolution,
        sum_multiple=False,
    )
    # only keep non-empty
    for s in sensors:
        if beliefs_by_sensor[s.name].empty:
            click.echo(f"No data found for sensor '{s.name}' (Id: {s.id})")
            beliefs_by_sensor.pop(s.name)
            sensors.remove(s)
    if len(beliefs_by_sensor.keys()) == 0:
        click.echo("No data found!")
        raise click.Abort()
    first_df = beliefs_by_sensor[sensors[0].name]

    # Build title
    if len(sensors) == 1:
        title = f"Beliefs for Sensor '{sensors[0].name}' (Id {sensors[0].id}).\n"
    else:
        title = f"Beliefs for Sensor(s) [{','.join([s.name for s in sensors])}], (Id(s): [{','.join([str(s.id) for s in sensors])}]).\n"
    title += f"Data spans {naturaldelta(duration)} and starts at {start}."
    if belief_time_before:
        title += f"\nOnly beliefs made before: {belief_time_before}."
    if source:
        title += f"\nSource: {source.description}"
    title += f"\nThe time resolution (x-axis) is {naturaldelta(min_resolution)}."

    uniplot.plot(
        [
            beliefs.event_value
            for beliefs in [beliefs_by_sensor[sn] for sn in [s.name for s in sensors]]
        ],
        title=title,
        color=True,
        lines=True,
        y_unit=first_df.sensor.unit
        if len(beliefs_by_sensor) == 1
        or all(sensor.unit == first_df.sensor.unit for sensor in sensors)
        else "",
        legend_labels=[s.name for s in sensors],
    )
Esempio n. 7
0
def test_normal_plotting():
    x = [math.sin(i / 20) + i / 300 for i in range(600)]
    plot(xs=x, ys=x, title="Sine wave")
Esempio n. 8
0
def test_just_single_point_plotting():
    """
    Testing this because this has caused problems since for a single point min == max
    """
    x = [2.34]
    plot(x)
Esempio n. 9
0
def test_massively_multi_series_plotting():
    x = [math.sin(i / 20) + i / 300 for i in range(600)]
    xt = np.array([x]).T
    plot(xt, title="Many colored dots", color=True)
Esempio n. 10
0
def test_normal_plotting_with_x_series():
    x = [math.sin(i / 20) + i / 300 for i in range(600)]
    plot(xs=x, ys=x, title="Diagonal")
Esempio n. 11
0
def test_random_line_plotting():
    xs = np.random.normal(size=100)
    ys = np.random.normal(size=100)
    plot(xs=xs, ys=ys, lines=True)