Node:line_plot, Next:, Previous:interval_bar_plot, Up:Top



Line and scatter plots

linetest3.png

Sample line plot

Below is the source code that produces the above chart. ../demos/linetest3.py

from pychart import *

theme.get_options()

data = chart_data.read_csv("lines.csv")

xaxis=axis.X(label="X", tic_interval=10)
yaxis=axis.Y(label="Y", tic_interval=10)
ar = area.T(x_range=(0,100), y_range=(0,100), x_axis=xaxis, y_axis=yaxis)
eb = error_bar.error_bar2(tic_len=5, hline_style=line_style.gray50)
ar.add_plot(line_plot.T(label="foo", data=data, error_bar=eb, y_error_minus_col=3),
            line_plot.T(label="bar", data=data, ycol=2, error_bar=eb, y_error_minus_col=3))
ar.draw()

tb = text_box.T(loc=(40, 130), text="This is\nimportant!", line_style=None)
tb.add_arrow((ar.x_pos(data[6][0]), ar.y_pos(data[6][1])), "cb")
tb.draw()

ar = area.T(loc=(200, 0), x_range=(0,100), y_range=(0,100),
            x_axis=xaxis, y_axis=yaxis, legend=legend.T())
ar.add_plot(line_plot.T(label="foo", data=data, data_label_format="/8{}%d"),
            line_plot.T(label="bar", data=data, ycol=2))
ar.draw()

Scatter plots can be created by setting the line_style attribute to None. See the next example. scattertest.png

Sample scatter plot

Below is the source code that produces the above chart. ../demos/scattertest.py

from pychart import *
import whrandom

def randomdata():
    data = []
    for i in range(0, 30):
        data.append((whrandom.random() * 1000, whrandom.random() * 1000))
    return data

theme.get_options()
chart_object.set_defaults(line_plot.T, line_style=None)

tick1 = tick_mark.Circle(size=2)
tick2 = tick_mark.Circle(size=2, fill_style=fill_style.black)
xaxis = axis.X(label="foo", format="/a-60{}%d")
yaxis = axis.Y(label="bar")

ar = area.T(x_axis=xaxis, y_axis=yaxis,
            x_grid_interval=100, x_grid_style=line_style.gray70_dash3,
            legend = legend.T(loc=(350, 50)), loc = (0, 0))

ar.add_plot(line_plot.T(label="plot1", data=randomdata(), tick_mark=tick1))
ar.add_plot(line_plot.T(label="plot2", data=randomdata(), tick_mark=tick2))
ar.draw()

xaxis = axis.X(label="foo", format="/a-30{}%d")
yaxis = axis.Y(label="bar")
ar = area.T(x_axis=xaxis, y_axis=yaxis,
            x_coord=log_coord.T(), y_coord=log_coord.T(), loc = (200, 0),
            legend = None)

ar.add_plot(line_plot.T(label="plot1", data=randomdata(), tick_mark=tick1))
ar.add_plot(line_plot.T(label="plot2", data=randomdata(), tick_mark=tick2))
ar.draw()