1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head><style type="text/css">
pre {background-color: #e0e0e0}
</style>
<link rel="STYLESHEET" href="pychart.css" type='text/css' />
<link rel="first" href="pychart.html" title='PyChart' />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="module-interval-bar-plot.html" />
<link rel="prev" href="module-area.html" />
<link rel="parent" href="pychart.html" />
<link rel="next" href="module-interval-bar-plot.html" />
<meta name='aesop' content='information' />
<title>7 Bar plots</title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="6.3 Legends"
href="module-legend.html"><img src='previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="PyChart"
href="pychart.html"><img src='up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="8 Interval bar plots"
href="module-interval-bar-plot.html"><img src='next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">PyChart</td>
<td class='online-navigation'><img src='blank.png'
border='0' height='32' alt='' width='32' /></td>
<td class='online-navigation'><img src='blank.png'
border='0' height='32' alt='' width='32' /></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-legend.html">6.3 Legends</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="pychart.html">PyChart</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-interval-bar-plot.html">8 Interval bar plots</A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION000700000000000000000"></A><a id='l2h-102' xml:id='l2h-102'></a>
<BR>
7 Bar plots
</H1>
<A NAME="module-bar-plot"></A>
<P>
<dl><dt><b><span class="typelabel">class</span> <tt id='l2h-104' xml:id='l2h-104' class="class">bar_plot.T</tt></b>
<dd>
This class draws a bar plot.
<P>
<IMG
WIDTH="957" HEIGHT="329" ALIGN="BOTTOM" BORDER="0"
SRC="./bartest.png"
ALT="Image bartest">
<P>
<b> Sample bar plot </b>
<P>
Below is the source code that produces the above chart.
../demos/bartest.py
<P>
<div class="verbatim"><pre>
from pychart import *
<a href="options.html"><a href="options.html">theme.</a>get_options</a>()
data = [(10, 20, 30, 5), (20, 65, 33, 5),
(30, 55, 30, 5), (40, 45, 51, 7), (50, 25, 27, 3)]
chart_object.set_defaults(<a href="module-area.html">area.T</a>, size = (150, 120), y_range = (0, None),
x_coord = <a href="module-coord.html">category_coord.T</a>(data, 0))
chart_object.set_defaults(<a href="module-bar-plot.html">bar_plot.T</a>, data = data)
# Draw the 1st graph. The Y upper bound is calculated automatically.
ar = <a href="module-area.html">area.T</a>(x_axis=<a href="module-axis.html">axis.</a>X(label="X label", format="/a-30{}%d"),
y_axis=<a href="module-axis.html">axis.</a>Y(label="Y label", tic_interval=10))
ar.add_plot(<a href="module-bar-plot.html">bar_plot.T</a>(label="foo", cluster=(0, 3)),
<a href="module-bar-plot.html">bar_plot.T</a>(label="bar", hcol=2, cluster=(1, 3)),
<a href="module-bar-plot.html">bar_plot.T</a>(label="baz", hcol=3, cluster=(2, 3)))
ar.draw()
ar = <a href="module-area.html">area.T</a>(legend = <a href="module-legend.html">legend.</a>T(), loc=(250,0),
x_axis=<a href="module-axis.html">axis.</a>X(label="X label", format="/a-30{}%d"),
y_axis=<a href="module-axis.html">axis.</a>Y(label="Y label", tic_interval=10))
bar_plot.fill_styles.reset();
plot1 = <a href="module-bar-plot.html">bar_plot.T</a>(label="foo")
plot2 = <a href="module-bar-plot.html">bar_plot.T</a>(label="bar", hcol=2, stack_on = plot1)
plot3 = <a href="module-bar-plot.html">bar_plot.T</a>(label="baz", hcol=3, stack_on = plot2)
ar.add_plot(plot1, plot2, plot3)
ar.draw()
</pre></div>
<P>
<IMG
WIDTH="407" HEIGHT="299" ALIGN="BOTTOM" BORDER="0"
SRC="./bartest2.png"
ALT="Image bartest2">
<P>
<b> Bar plot with error bars </b>
<P>
Below is the source code that produces the above chart.
../demos/bartest2.py
<P>
<div class="verbatim"><pre>
from pychart import *
<a href="options.html"><a href="options.html">theme.</a>get_options</a>()
data = [(10, 20, 3.0), (20, 65, 2.5),
(30, 55, 5.0), (40, 45, 3.0), (50, 25, 2.0)]
ar = <a href="module-area.html">area.T</a>(x_axis=<a href="module-axis.html">axis.</a>X(label="X", format="/a-30{}%d", tic_interval=20),
y_axis = <a href="module-axis.html">axis.</a>Y())
ar.add_plot(<a href="module-bar-plot.html">bar_plot.T</a>(data=data,
line_style=None, fill_style = <a href="module-fill-style.html">fill_style.</a>gray50,
error_bar = <a href="module-error-bar.html">error_bar.</a>bar2, error_minus_col=2))
ar.draw()
</pre></div>
</dl>
<P>
The list the attributes understood by an <code>bar_plot.T</code> object follow:
<P>
<dl><dt><b><tt id='l2h-105' xml:id='l2h-105' class="member">bcol</tt></b></dt>
<dd>
<b>Type:</b> int
<b>Default:</b> 0.
<P>
Specifies the column from which base values (i.e., X values when attribute "direction" is "vertical", Y values otherwise) are extracted.
The
combination of "data", "bcol", and "hcol" attributes defines
the set of boxes drawn by this chart. See the
below example:
<P>
<div class="verbatim"><pre>
d = [[5,10], [7,22], [8,25]]
p = <a href="module-bar-plot.html">bar_plot.T</a>(data = d, bcol = 1, hcol = 2)
</pre></div>
<P>
Here, three bars will be drawn. The X values of the bars
will be 5, 7, and 8. The Y values of the bars will be
10, 22, and 25, respectively. (In practice, because
the values of bcol and hcol defaults to 1 and 2, you can
write the above example just as "p = bar_plot.T(data = d)".
<P>
</dl>
<dl><dt><b><tt id='l2h-106' xml:id='l2h-106' class="member">cluster</tt></b></dt>
<dd>
<b>Type:</b> tuple
<b>Default:</b> (0, 1).
<P>
This attribute is used to
cluster multiple bar plots side by side in a single chart.
The value should be a tuple of two integers. The second value should be equal to the total number of bar plots in the chart. The first value should be the relative position of this chart; 0 places this chart the leftmost, and N-1
(where N is the 2nd value of this attribute) places this chart the rightmost. Consider the below example:
<P>
<div class="verbatim"><pre>
a = <a href="module-area.html">area.T</a>(...)
p1 = <a href="module-bar-plot.html">bar_plot.T</a>(data = [[1,20][2,30]], cluster=(0,2))
p2 = <a href="module-bar-plot.html">bar_plot.T</a>(data = [[1,25],[2,10]], cluster=(1,2))
a.add_plot(p1, p2)
a.draw()
</pre></div>
<P>
In this example, one group of bars will be drawn side-by-side at
position x=1, one with height 20, the other with height 25. The
other two bars will be drawn side by side at position x=2, one
with height 30 and the other with height 10.
<P>
</dl>
<dl><dt><b><tt id='l2h-107' xml:id='l2h-107' class="member">cluster_sep</tt></b></dt>
<dd>
<b>Type:</b> length in points ( See Section <A href="unit.html#unit">4</A>)
<b>Default:</b> 0.
<P>
The separation between
clustered boxes.
</dl>
<dl><dt><b><tt id='l2h-108' xml:id='l2h-108' class="member">data</tt></b></dt>
<dd>
<b>Type:</b> any
<b>Default:</b> None.
<P>
Specifies the data points. See Section <A href="module-chart-data.html#module-chart-data">5</A>
</dl>
<dl><dt><b><tt id='l2h-109' xml:id='l2h-109' class="member">data_label_format</tt></b></dt>
<dd>
<b>Type:</b> printf format string
<b>Default:</b> None.
<P>
The
format string for the label displayed besides each
bar. It can be a `printf' style format
string, or a two-parameter function that
takes (x,y) values and returns a string. The appearance of the string produced here can be
controlled using escape sequences. See Section <A href="module-font.html#module-font">17</A>
</dl>
<dl><dt><b><tt id='l2h-110' xml:id='l2h-110' class="member">data_label_offset</tt></b></dt>
<dd>
<b>Type:</b> (x,y) or None
<b>Default:</b> (0, 5).
<P>
The location of data labels relative to the sample point. See also attribute data_label_format.
</dl>
<dl><dt><b><tt id='l2h-111' xml:id='l2h-111' class="member">direction</tt></b></dt>
<dd>
<b>Type:</b> str
<b>Default:</b> "vertical".
<P>
The direction the growth of the bars. The value is either 'horizontal'
or 'vertical'.
</dl>
<dl><dt><b><tt id='l2h-112' xml:id='l2h-112' class="member">error_bar</tt></b></dt>
<dd>
<b>Type:</b> error_bar.T
( see Section <A href="module-error-bar.html#module-error-bar">9.2</A>)
<b>Default:</b> None.
<P>
Specifies the style of the error bar. See Section <A href="module-error-bar.html#module-error-bar">9.2</A>
</dl>
<dl><dt><b><tt id='l2h-113' xml:id='l2h-113' class="member">error_minus_col</tt></b></dt>
<dd>
<b>Type:</b> int
<b>Default:</b> -1.
<P>
Specifies the column from which the depth of the errorbar is extracted. This attribute is meaningful only when
error_bar != None.
<P>
</dl>
<dl><dt><b><tt id='l2h-114' xml:id='l2h-114' class="member">error_plus_col</tt></b></dt>
<dd>
<b>Type:</b> int
<b>Default:</b> -1.
<P>
The depth of the errorbar is extracted from
this column in data. This attribute is meaningful only
when error_bar != None.
</dl>
<dl><dt><b><tt id='l2h-115' xml:id='l2h-115' class="member">fill_style</tt></b></dt>
<dd>
<b>Type:</b> fill_style.T
( see Section <A href="module-fill-style.html#module-fill-style">16</A>)
<b>Default:</b> The style is picked from standard styles round-robin..
<P>
Defines the fill style of each box.
</dl>
<dl><dt><b><tt id='l2h-116' xml:id='l2h-116' class="member">hcol</tt></b></dt>
<dd>
<b>Type:</b> int
<b>Default:</b> 1.
<P>
The column from which the height of each bar is extracted.
See also the description of the 'bcol' attribute.
</dl>
<dl><dt><b><tt id='l2h-117' xml:id='l2h-117' class="member">label</tt></b></dt>
<dd>
<b>Type:</b> str
<b>Default:</b> "???".
<P>
The label to be displayed in the legend. See Section <A href="module-legend.html#module-legend">6.3</A>, See Section <A href="module-font.html#module-font">17</A>
</dl>
<dl><dt><b><tt id='l2h-118' xml:id='l2h-118' class="member">legend_fill_style</tt></b></dt>
<dd>
<b>Type:</b> fill_style.T
(see Section <A href="module-fill-style.html#module-fill-style">16</A>)
<b>Default:</b> None.
<P>
The fill style used to draw a legend entry. Usually, the value is None, meaning that the value of "fill_style" attribute is used.
</dl>
<dl><dt><b><tt id='l2h-119' xml:id='l2h-119' class="member">legend_line_style</tt></b></dt>
<dd>
<b>Type:</b> line_style.T
( see Section <A href="module-line-style.html#module-line-style">14</A>)
<b>Default:</b> None.
<P>
The line style used to draw a legend entry. Usually, the value is None, meaning that the value of "line_style" attribute is used.
</dl>
<dl><dt><b><tt id='l2h-120' xml:id='l2h-120' class="member">line_style</tt></b></dt>
<dd>
<b>Type:</b> line_style.T
( see Section <A href="module-line-style.html#module-line-style">14</A>)
<b>Default:</b> line_style.black.
<P>
The style of the outer frame of each box.
</dl>
<dl><dt><b><tt id='l2h-121' xml:id='l2h-121' class="member">qerror_minus_col</tt></b></dt>
<dd>
<b>Type:</b> int
<b>Default:</b> -1.
<P>
The depth of the "quartile" errorbar is extracted from
this column in data. This attribute is meaningful only
when error_bar != None.
</dl>
<dl><dt><b><tt id='l2h-122' xml:id='l2h-122' class="member">qerror_plus_col</tt></b></dt>
<dd>
<b>Type:</b> int
<b>Default:</b> -1.
<P>
The depth of the "quartile" errorbar is extracted from
this column in data. This attribute is meaningful only
when error_bar != None.
</dl>
<dl><dt><b><tt id='l2h-123' xml:id='l2h-123' class="member">stack_on</tt></b></dt>
<dd>
<b>Type:</b> any
<b>Default:</b> None.
<P>
The value must be either None or bar_plot.T. If not None, bars of this plot are stacked on top of another bar plot.
</dl>
<dl><dt><b><tt id='l2h-124' xml:id='l2h-124' class="member">width</tt></b></dt>
<dd>
<b>Type:</b> length in points ( See Section <A href="unit.html#unit">4</A>)
<b>Default:</b> 5.
<P>
Width of each box.
<P>
</dl>
<P>
<DIV CLASS="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="6.3 Legends"
href="module-legend.html"><img src='previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="PyChart"
href="pychart.html"><img src='up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="8 Interval bar plots"
href="module-interval-bar-plot.html"><img src='next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">PyChart</td>
<td class='online-navigation'><img src='blank.png'
border='0' height='32' alt='' width='32' /></td>
<td class='online-navigation'><img src='blank.png'
border='0' height='32' alt='' width='32' /></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-legend.html">6.3 Legends</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="pychart.html">PyChart</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-interval-bar-plot.html">8 Interval bar plots</A>
</div>
</div>
<hr />
<span class="release-info">Documentation released on July 2, 2005.</span>
</DIV>
<!--End of Navigation Panel-->
</BODY>
</HTML>
|