Esempio n. 1
0
def test_hide_axis():
    """Test with hidden axis"""

    cs_1 = cartesius.CoordinateSystem(bounds=(-2.5, 2.5, -2.5, 2.5))
    cs_1.add(elements.Axis(horizontal=True, hide=True))
    cs_1.add(elements.Axis(vertical=True))
    cs_1.add(
        charts.Function(lambda x: x * math.sin(x * x),
                        start=-4,
                        end=5,
                        step=0.02,
                        color=(0, 0, 255)))

    cs_2 = cartesius.CoordinateSystem(bounds=(-2.5, 2.5, -2.5, 2.5))
    cs_2.add(elements.Axis(horizontal=True))
    cs_2.add(elements.Axis(vertical=True, hide=True))
    cs_2.add(
        charts.Function(lambda x: x * math.sin(x * x),
                        start=-4,
                        end=5,
                        step=0.02,
                        color=(0, 0, 255)))

    return cs_1.draw(150, 150), cs_2.draw(150, 150), cs_1.draw(
        150, 150, antialiasing=True), cs_2.draw(150, 150, antialiasing=True)
Esempio n. 2
0
def test_filled_function():
    """ Line function and normal function but with filled graph"""
    coordinate_system = cartesius.CoordinateSystem()

    f = lambda x: math.sin(x) * 2
    coordinate_system.add(
        charts.Function(f, start=-4, end=5, step=0.02, color=0x0000ff))

    g = lambda x: math.sin(x) * 2
    coordinate_system.add(
        charts.Function(g,
                        start=1,
                        end=4,
                        step=0.02,
                        fill_color=(200, 255, 200)))

    return coordinate_system.draw(300, 200), coordinate_system.draw(
        300, 200, antialiasing=True)
Esempio n. 3
0
def test_function_with_custom_bounds():
    """Same function, but with custom coordinate system bounds"""
    coordinate_system = cartesius.CoordinateSystem(bounds=(-32, 20, -3, 3))

    f = lambda x: math.sin(x) * 2
    coordinate_system.add(
        charts.Function(f, start=-4, end=5, step=0.02, color=(0, 0, 255)))

    return coordinate_system.draw(300, 200), coordinate_system.draw(
        300, 200, antialiasing=True)
Esempio n. 4
0
def test_function():
    """ Function math.sin from -4 to 5"""
    coordinate_system = cartesius.CoordinateSystem()

    f = lambda x: math.sin(x) * 2
    coordinate_system.add(
        charts.Function(f, start=-4, end=5, step=0.02, color=0x0000ff))

    return coordinate_system.draw(300, 200), coordinate_system.draw(
        300, 200, antialiasing=True)
Esempio n. 5
0
def test_detached_axes():
    """ Detached axes"""
    coordinate_system = cartesius.CoordinateSystem(bounds=(-10, 10, -10, 10))

    coordinate_system.add(
        charts.Function(lambda x: x * math.sin(x * x),
                        start=-4,
                        end=5,
                        step=0.02,
                        color=(0, 0, 255)))

    # Standard axes:
    coordinate_system.add(elements.Axis(horizontal=True, points=2))
    coordinate_system.add(elements.Axis(vertical=True, labels=2))

    # You can have only one horizontal and one vertical standard axis and, if you add
    # more -- the newer will overwrite the older.

    # But, you can make as many as you want *detached axes*. These are just like normal
    # ones, but their center is not (0,0).

    # Detached:
    detached_axes_center = (-5, 4)

    coordinate_system.add(
        elements.Axis(horizontal=True,
                      points=2,
                      labels=2,
                      detached_center=detached_axes_center,
                      color=(255, 0, 0)))
    coordinate_system.add(
        elements.Axis(vertical=True,
                      points=2,
                      labels=2,
                      detached_center=detached_axes_center,
                      color=(0, 0, 255)))

    # Another pair of detached axes with hidden negative/positive halfs:
    detached_axes_center = (4, -5)
    coordinate_system.add(
        elements.Axis(horizontal=True,
                      points=2,
                      labels=2,
                      detached_center=detached_axes_center,
                      hide_negative=True))
    coordinate_system.add(
        elements.Axis(vertical=True,
                      points=2,
                      labels=2,
                      detached_center=detached_axes_center,
                      hide_positive=True))

    return coordinate_system.draw(300, 200), coordinate_system.draw(
        300, 200, antialiasing=True)
Esempio n. 6
0
def test_filled_function():
    """ Previous example with grid behind graphs """
    coordinate_system = cartesius.CoordinateSystem()

    # Grid:
    coordinate_system.add(elements.Grid(1, 1))

    f = lambda x: math.sin(x) * 2
    coordinate_system.add(
        charts.Function(f, start=-4, end=5, step=0.02, color=(0, 0, 255)))

    g = lambda x: math.sin(x) * 2
    coordinate_system.add(
        charts.Function(g,
                        start=1,
                        end=4,
                        step=0.02,
                        fill_color=(200, 255, 200)))

    return coordinate_system.draw(300, 200), coordinate_system.draw(
        300, 200, antialiasing=True)
Esempio n. 7
0
def test_with_two_horizontal_grids():
    """Two horizontal grids"""
    coordinate_system = cartesius.CoordinateSystem()

    coordinate_system.add(elements.Grid(0.25, None, color=(200, 200, 200)))
    coordinate_system.add(elements.Grid(1, None, color=(250, 50, 50)))

    f = lambda x: math.sin(x) * 2
    coordinate_system.add(
        charts.Function(f, start=-4, end=5, step=0.02, color=(0, 0, 255)))

    return coordinate_system.draw(300, 200), coordinate_system.draw(
        300, 200, antialiasing=True)
Esempio n. 8
0
def test_filled_transparent_graphs():
    """ Two functions """
    coordinate_system = cartesius.CoordinateSystem()

    coordinate_system.add(
        charts.Function(math.sin,
                        start=-4,
                        end=5,
                        step=0.02,
                        fill_color=(0, 0, 255),
                        transparency_mask=100))

    coordinate_system.add(
        charts.Function(math.cos,
                        start=-4,
                        end=5,
                        step=0.02,
                        fill_color=(200, 255, 200),
                        transparency_mask=100))

    return coordinate_system.draw(300, 200), coordinate_system.draw(
        300, 200, antialiasing=True)
Esempio n. 9
0
def test_hide_axis_positive_or_negative_parts():
    """Hide positive and/or negative parts of axes"""
    cs_1 = cartesius.CoordinateSystem(bounds=(-2.5, 2.5, -2.5, 2.5))
    cs_1.add(
        charts.Function(lambda x: x * math.sin(x * x),
                        start=-4,
                        end=5,
                        step=0.02,
                        color=(0, 0, 255)))
    cs_1.add(elements.Axis(horizontal=True, hide_positive=True))
    cs_1.add(elements.Axis(vertical=True, hide_positive=True))

    cs_2 = cartesius.CoordinateSystem(bounds=(-2.5, 2.5, -2.5, 2.5))
    cs_2.add(
        charts.Function(lambda x: x * math.sin(x * x),
                        start=-4,
                        end=5,
                        step=0.02,
                        color=(0, 0, 255)))
    cs_2.add(elements.Axis(horizontal=True, hide_negative=True))
    cs_2.add(elements.Axis(vertical=True, hide_negative=True))

    return cs_1.draw(150, 150), cs_2.draw(150, 150), cs_1.draw(
        150, 150, antialiasing=True), cs_2.draw(150, 150, antialiasing=True)
Esempio n. 10
0
def test_axis_custom_colors():
    """Axis with custom colors"""
    coordinate_system = cartesius.CoordinateSystem()

    coordinate_system.add(
        elements.Axis(horizontal=True,
                      color=(255, 0, 0),
                      labels=1,
                      points=0.25))
    coordinate_system.add(
        elements.Axis(vertical=True, color=(0, 255, 0), labels=2, points=1))

    f = lambda x: x * math.sin(x * x)
    coordinate_system.add(
        charts.Function(f, start=-4, end=5, step=0.02, color=(0, 0, 255)))

    return coordinate_system.draw(300, 200), coordinate_system.draw(
        300, 200, antialiasing=True)
Esempio n. 11
0
def test_axis_with_custom_labels():
    """Axis with custom label positions and decorations:"""
    coordinate_system = cartesius.CoordinateSystem()

    coordinate_system.add(elements.Axis(horizontal=True, labels=1,
                                        points=0.25))
    coordinate_system.add(
        elements.Axis(vertical=True,
                      labels=2,
                      labels_decorator=lambda x: 'speed=%sm/s' % x,
                      points=1))

    f = lambda x: math.sin(x) * 2
    coordinate_system.add(
        charts.Function(f, start=-4, end=5, step=0.02, color=(0, 0, 255)))

    return coordinate_system.draw(300, 200), coordinate_system.draw(
        300, 200, antialiasing=True)