PyGDChart Tutorial
Getting Started
This section gives a quick overview of the features of the PyGDChart library by working through a simple example. We first show the example program, and the graph it produces, in full. Then we proceed with a line-by-line analysis, introducing the basic workings of PyGDChart as we go along.
이 섹션은 간단한 예제를 통해서 PyGDChart 라이브러리에 대해서 빠르게 특징들에 대해서 알려주려고 합니다. 첫번재로 우리는 예제 프로그램을 보여줍니다. 그리고 이 예제는 자세히(?) 그래프를 만들지요. 그리고 우리는 줄 단위로 분석을 하고 그리고 PyGDChart로 작동하는 기본 원리에 대해서 소개하려고 합니다.
The Code
- import gdchart
x = gdchart.Bar3D()
x.width = 250
x.height = 250
x.xtitle = "Weekday"
x.ytitle = "Percentage"
x.title = "Example Graph"
x.ext_color = [ "white", "yellow", "red", "blue", "green"]
x.setData([20, 100, 80, 30, 50])
x.setLabels(["Mon", "Tue", "Wed", "Thu", "Fri"])
x.draw("simple.png")
Explanation
Choosing a Chart Class
- x = gdchart.Bar3D()
The PyGDChart library is based around a number of chart classes, each of which represents a different chart style. The first step in using PyGDChart is usually to instantiate one of these classes. In this case, we will be drawing a 3D bar graph.
PyGDChart 라이브러리는 수ㅈ 많은 차트 클래스에... 기반하고 있으며, 각 클래스들은 다른 차트 스타일을 보여준다. 이 라이브러리를 이용한 첫 번째 스텝은 이 클래스들 중에서 하나로 예시를 들려고 한다. 이 경우에 우리는 3D바 그래프를 그릴려고 한다.
Setting Options
- x.width = 250
x.height = 250
x.xtitle = "Weekday"
x.ytitle = "Percentage"
x.title = "Example Graph"
x.ext_color = [ "white", "yellow", "red", "blue", "green"]
Although they look like simple object attributes, PyGDChart options are actually "smart" properties. Whenever you assign to, or retreive the value of, an option, a certain amount of checking and conversion code is run. This allows us to ensure that values assigned to options are appropriate - for instance, we can prevent a user from assigning a string to an option when the underlying C library expects an integer.
위 에 있는 것들은 간단 오브젝트 속성을 가지고 있기는 하지만, 이 라이브러리의 옵션은 실제로 "스마트" 속성을 가지고 있다. 당신이 확실한 양의 체킹하기 값(옵션)을 할당을 또는 검색을 언제하든지 간에 그리고 컨버젼 코드는 실행한다.(역, 무슨 말인지) 이 것은 예를 들면 우리에게 값이 정확한 옵션을 할당하는 것에 대해서 보장해준다. 그래서 근원적인 C라이브러리는 integer를 기대할때 우리는 유저가 문자열을 옵션에 할당하는 것을 막을 수가 있다.(역, -_-a ㅠㅠ)
"Smart" options can also make things more convenient by performing some types of automatic data conversion. Note that the code snippet above uses descriptive names to specify colours. In the underlying library, however, colours are stored as integers - colour names are converted to the appropriate integer values on assignment. PyGDChart's colour handling capabilities are discussed in greater depth later in this manual.
" 스마트" 옵션은 물론 몇몇 타입들인 자동 데이타 컨버젼스를 수행함으로써 이러한 것들을 좀더 편리하게 만들 수 있다. 위에 있는 약간의 코드들은 컬로러 표시되어진 설명적인-_- 이름을 사용한다. 그 기초를 이루는 라이브러리에서 그러나 색깔은 정수로 저장되어 진다 - 색깔로된 이름들은 할당되어진 것에 대해서 정확하게 정수로 저장된다. PyGDChart의 컬러 핸들링 가능성은 나중에 이 메뉴얼에서 깊이 있게 이야기되어진다.
Data and Labels
- x.setData([20, 100, 80, 30, 50])
Each chart type has a .setData() method, but different chart types may require different data formats. Bar graphs, like the one in the example, can be specified using one or more lists of values. If were drawing a floating bar graph, however, the data format would be more complex, since we would have to specify both the upper and lower bounds for every bar. The data requirements for the various chart types are discussed in the appropriate sections elsewhere in this manual.
조금각 차트 타입은 setData() 메소드를 가진다 그러나 다른 차트 타입들은 다른 데이타 포맷을 요구한다. 예제에서 있는 바 그래프 처럼, 이 것은 더 복잡하다 모든 바에서 위 아래 바운드 모두를 기술해야 하기 때문이다. 다양한 차트 타입에 대한 데이타 요구는 이 메뉴얼.. 다른 곳인... 정확한 섹션에서 이야기가 되어질 것 이다.
- x.setLabels(["Mon", "Tue", "Wed", "Thu", "Fri"])
The .setLabels method is used to specify the labels that appear on the X axis of a graph. In order to avoid ambiguity, PyGDChart ensures that the number of labels conforms with the number of data points along the X axis.
setLable 메소드는 그래프의 X 좌표에 나타나는 라벨에 기술하는데 사용되어 진다. 모호함을 없에기 위해서 이 라이브러리는 많은 라 벨이 X좌표를 따른 많은 데이타 점들을 따르는 것을 보증한다.
Common Interface
All graph and pie classes share a common basic interface:
모든 그래프와 파이 클래스는 콤온 베이직 인터페리를 공유한다.
setOption(option, value)
Set an option by option name and value. This method also does data type conversion (see the discussion of colour handling), and type conformance checks.
옵션 이름 그리고 값에 의해 옵션을 셋팅한다. 이 메소드는 물론 데이타 타입 컨번젼스를 한다. (컬러 핸들링때 보자) 그리고 타 입 일치를 체크한다.
getOption(option)
Retrieve the value of an option by name.
옵션의 값은 이름에 의해서 검색한다.
getAllOptions()
Retrieve a dictionary of all option-value pairs.
사전형의 모든 옵션값은 짝으로 검색한다.
restoreDefaultOptions()
Restore the values of all options to the defaults for this graph type.
이 그래프 타입을 위해서 모든 옵션 값을 기본값으로 복구한다.
setLabels([label1, label2, ...])
Set the X-axis labels for Graph types, and per-slice labels for Pie charts. The number of arguments passed to this function should correspond with the number of discrete data points to be plotted.
그래프 타입을 위한 X 좌표 라벨을 그리고 파이 차트를 위한 per-slice 라벨을 셋팅한다. 이 함수를 통과하는 많은 인자들은 좌표에 그려진 많은 분리된 데이타 점에 대응되어야 한다.
setData(data1, [data2, ...])
Set the data to be charted. The data format expected differs from chart type to chart type - please see the corresponding chart section for more information.
데이타를 차트화한다. 예상되어진 데이타 포맷은 차트 타입과 차트 타입간에 다르다. 좀 더 자세한 것은 대응되는 차트 섹션을 보라.
draw(filespec)
Draw the graph to the specified file. If the filespec argument is a string, it will be treated as the path to a file. Otherwise, filespec is
assumed to be a Python file object.
파일기술되어진 파일에 그래프를 그린다. 파일 스텍 인자가 문자열이면 파일에 경로로서 조정이 되어진다. 만약 그렇지 않으면 파일 스펙은 파이썬 오브젝트로서 가정되어 진다.
Options as properties
All options are also exposed as properties. Getting and setting an option as a property, is functionally identical to making the corresponding getOption and setOption calls.
모든 옵션은 물론 속성으로서 노출되어 있다. 속성으로서 옵션을 얻거나 셋팅하는 것은 대응되는 getOption 이나 setOption을 콜하는 것으 기능적으 로 동일하다.
Graphs
PyGDChart exposes a set of classes that allow the programmer to draw various graphs on classical Cartesian axes. All of these Graph types share an underlying set of options, and obey the same basic interface. Please see sections discussing particular graph types for more information.
해준다..이 라이브러리는 클래스들을 노출 시키는데... 이 것들은 프로그래머가 클래식컬한 데카르트의 좌표?? 위에서 다양한 그래프를 그릴 수 있게 이러한 그래프 타입의 모든 것은 기초되는 옵션들을 공유한다. 그리고 같은 기초되는 인터페이스를 준수한다. 조금 더 자세한 것은 특별한 그래프 타입에 관해 토론하는 섹션을 봐라
Interface
In addition to the common interface Graph types expose the following methods:
게다가 공통의 인터페이스는 그래프 타입은 아래의 메소드를 노출한다.
setScatter(scatterpoints)
<> Here, scatterpoints is a list of Scatter objects. See the section on Scatter Graphs for an in-depth discussion of the use of this method.
여기, scatterpoints는 스케터 오브젝트의 목록이다. 이 미세도를 사용에 대한 깊이 있는 토론에 대한 것은 Scatter 그래프 섹션을 보라
annotate(point=0, note="", colour="white")
The GDChart library allows the user to add a single annotation to a given graph. The point argument indicates the X-axis offset of the annotation, note is the annotation text itself, and colour is the annotation colour.
이 라이브러니는 유저가 주어진 그래프에 싱글 주석을 추가할 수 있게 해준다.. Point 인자는 주석의 x 좌표 오프셋을 나타낸다. note는 그래프에서의 주소 문자열을 말하고, colour은 주석의 색깔이다.
clearAnnotation()
Clear the annotation, if any.
만약 주석이 있다면, 주석을 깨끗하게 한다.??
Colours
Both PyGDChart and GDChart itself store and manipulate colours as RGB integers. Users will be familiar with RGB colour definitions from other contexts - for instance, colours in HTML are often specified in the form "#RRGGBB", where each component is a hex number between 0 and 256. Since the naked RGB integer is cumbersome to work with, the PyGDChart library provides a number of simple facilities to make the programmer's life easier.
바 로... PyGDChart 와 GDChart 모두... 색들을 RGB 정수로서 저장하고 관리한다. 유저는 다른 문맥(역, html 등등)으로 부터 RGB 컬러 정의에 친근하다.(역, 아-_-;;;) 예를 들면 HTML에서 색상은 종종 "#RRGGBB" 형태로서 기술되어지고, 각 구성요소는 0 에서 255의 16진수로 이루어진다.
The RGB Class
The first of the colour manipulation facilities provided by PyGDChart is the RGB class. This class is simply a way to collect and manipulate the components of a normal RGB colour definition. It is instantiated as follows:
PyGDChart에 의해서 제공되어지는 첫번째로...쓸만한 것은 RGB 클래스이다. 이 클래스는 보통의 RGB 색상 정의 구성요소를 다루거나 수집하는 간단한 방법이다. 아래에 예시가 나왔다.
- x = gdchart.RGB(r, g, b)
After instantiation, an RGB object exposes the attributes r, g, and b, which can be inspected and set independently. RGB objects have an __int__ method that converts the RGB colour definition to the correct numerical value. As such, an RGB object can be used wherever a colour definition is required.
__int__ 예에서... RGB 오브젝트는 r, g, b을 노출하고 있고, 이 것은 면밀히 살펴질 수 있고 그리고 독립적으로 설정되어 질 수 있다. RGB 오브젝트는 메소드를 가지고 있는데 이 것은 RGB 색상 정의를 정확한 숫자의 값으로 바꾼다. 그래서... RGB 오브젝트는 색상 정의가 요구되어지는 어디에서든지 사용되어 질 수 있다.
The rgbFactory() function
The rgbFactory() function is an easy way to manufacture RGB objects corresponding to common colours:
rgbFactory 함수는 공통의 색깔에 대응하는 RGB 오브젝트를 만드는.... 쉬운 방법이다.
- x = gdchart.rgbFactory("blue")
At the moment only entries for "blue", "red", "green", "orange", "white", "black" and "yellow" are provided, but this list will grow in future.
지금... 여러색에 대한 엔트리는 제공되어 진다. 그러나 이러한 목록은 미래에.... 바뀔 수도 있다???
Colours and PyGDChart
From the preceding sections, we already know of two major ways to specify a colour to PyGDChart. Firstly, as a plain integer:
앞 섹션에서.. 우리는 이미 이 라이브러리에서 색을 기술하는 중요한... 2가지 방법을 배웠다. 첫번째로 plain 정수로서...
- x.bg_color = 0x3232CC
And secondly, as an RGB object:
두번째로.. RGB 오브젝트로서..
- x.bg_color = gdchart.rgbFactory("blue")
From the latter example, however, an even more convenient way of specifying a colour leaps to mind. Since options in PyGDChart are "smart", we can check wether an option has been passed a string, and call rgbFactory automatically to generate an RGB object. This leads us to the third way of specifying colours in PyGDChart - simply by using a descriptive string:
마 지막 예제에서... 그러나 색을 기술하는 조금 더 편리한 방법이... 보인다=_=a. 이 라이브러리에서 옵션은 "스마트"하다. 우리는 옵션이 문자열을 통과되어지든.. 않하든 간에 체크할 수 있다-.-;;;; 그리고 RGB 오브젝트를 자동적으로 생성하는 rgbFacotry를 생성한다.
이 것응 루리를 세번째 방법을 이끈는데 이 것은 이 라이블러이에서 색을 기술하는 것이다. - 설명적인 문자열을 사용함으로 간단하게...
- x.bg_color = "blue"
위에 처럼.... ^^:
History
Last edited on 04/24/2008 17:53 by noish
Comments (0)