| 1 | .. index:: options |
|---|
| 2 | .. _options: |
|---|
| 3 | |
|---|
| 4 | ******* |
|---|
| 5 | Options |
|---|
| 6 | ******* |
|---|
| 7 | |
|---|
| 8 | Many properties of graphs in PyCha can be easily customized. Options include |
|---|
| 9 | colors, font sizes, widths, placements, and opacity. You can get a feel for what |
|---|
| 10 | the options do with :ref:`chavier` (frontend gui for PyCha). |
|---|
| 11 | |
|---|
| 12 | .. index:: default options |
|---|
| 13 | .. _default-options: |
|---|
| 14 | |
|---|
| 15 | Default Options |
|---|
| 16 | =============== |
|---|
| 17 | |
|---|
| 18 | The default options are: |
|---|
| 19 | |
|---|
| 20 | :: |
|---|
| 21 | |
|---|
| 22 | DEFAULT_OPTIONS = Option( |
|---|
| 23 | axis=Option( |
|---|
| 24 | lineWidth=1.0, |
|---|
| 25 | lineColor='#0f0000', |
|---|
| 26 | tickSize=3.0, |
|---|
| 27 | labelColor='#666666', |
|---|
| 28 | labelFont='Tahoma', |
|---|
| 29 | labelFontSize=9, |
|---|
| 30 | labelWidth=50.0, |
|---|
| 31 | x=Option( |
|---|
| 32 | hide=False, |
|---|
| 33 | ticks=None, |
|---|
| 34 | tickCount=10, |
|---|
| 35 | tickPrecision=1, |
|---|
| 36 | range=None, |
|---|
| 37 | rotate=None, |
|---|
| 38 | label=None, |
|---|
| 39 | ), |
|---|
| 40 | y=Option( |
|---|
| 41 | hide=False, |
|---|
| 42 | ticks=None, |
|---|
| 43 | tickCount=10, |
|---|
| 44 | tickPrecision=1, |
|---|
| 45 | range=None, |
|---|
| 46 | rotate=None, |
|---|
| 47 | label=None, |
|---|
| 48 | ), |
|---|
| 49 | ), |
|---|
| 50 | background=Option( |
|---|
| 51 | hide=False, |
|---|
| 52 | baseColor=None, |
|---|
| 53 | chartColor='#f5f5f5', |
|---|
| 54 | lineColor='#ffffff', |
|---|
| 55 | lineWidth=1.5, |
|---|
| 56 | ), |
|---|
| 57 | legend=Option( |
|---|
| 58 | opacity=0.8, |
|---|
| 59 | borderColor='#000000', |
|---|
| 60 | hide=False, |
|---|
| 61 | position=Option(top=20, left=40, bottom=None, right=None), |
|---|
| 62 | ), |
|---|
| 63 | padding=Option( |
|---|
| 64 | left=30, |
|---|
| 65 | right=30, |
|---|
| 66 | top=30, |
|---|
| 67 | bottom=30, |
|---|
| 68 | ), |
|---|
| 69 | stroke=Option( |
|---|
| 70 | color='#ffffff', |
|---|
| 71 | hide=False, |
|---|
| 72 | shadow=True, |
|---|
| 73 | width=2 |
|---|
| 74 | ), |
|---|
| 75 | fillOpacity=1.0, |
|---|
| 76 | shouldFill=True, |
|---|
| 77 | barWidthFillFraction=0.75, |
|---|
| 78 | pieRadius=0.4, |
|---|
| 79 | colorScheme=DEFAULT_COLOR, |
|---|
| 80 | title=None, |
|---|
| 81 | titleFont='Tahoma', |
|---|
| 82 | titleFontSize=12, |
|---|
| 83 | ) |
|---|
| 84 | |
|---|
| 85 | .. index:: changing defaults |
|---|
| 86 | .. _changing-defaults: |
|---|
| 87 | |
|---|
| 88 | Changing Defaults |
|---|
| 89 | ================= |
|---|
| 90 | |
|---|
| 91 | The default options can be changed using a Python dictionary (``options = {}``). |
|---|
| 92 | A typical user option dictionary looks like:: |
|---|
| 93 | |
|---|
| 94 | options = { |
|---|
| 95 | 'axis': { |
|---|
| 96 | 'x': { |
|---|
| 97 | 'ticks': [dict(v=i, label=l[0]) for i, l in enumerate(Tainan)], |
|---|
| 98 | 'label': 'Month', |
|---|
| 99 | 'rotate': 25, |
|---|
| 100 | }, |
|---|
| 101 | 'y': { |
|---|
| 102 | 'tickCount': 4, |
|---|
| 103 | 'rotate': 25, |
|---|
| 104 | 'label': 'Precipitation (mm)' |
|---|
| 105 | } |
|---|
| 106 | }, |
|---|
| 107 | 'background': { |
|---|
| 108 | 'chartColor': '#d8e7ec', |
|---|
| 109 | 'baseColor': '#efebe7', |
|---|
| 110 | 'lineColor': '#444444' |
|---|
| 111 | }, |
|---|
| 112 | 'colorScheme': '#6eafc1', |
|---|
| 113 | 'legend': { |
|---|
| 114 | 'hide': False, |
|---|
| 115 | 'position': {'top': 5, 'left': 5}, |
|---|
| 116 | }, |
|---|
| 117 | 'padding': { |
|---|
| 118 | 'left': 135, |
|---|
| 119 | 'bottom': 55, |
|---|
| 120 | }, |
|---|
| 121 | 'stroke': {'hide': True}, |
|---|
| 122 | 'title': 'Monthly Precipitation' |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | .. index:: axis options |
|---|
| 126 | .. _axis-options: |
|---|
| 127 | |
|---|
| 128 | Axis Options |
|---|
| 129 | ------------ |
|---|
| 130 | |
|---|
| 131 | .. These terms should be bold by default, not sure why they are not |
|---|
| 132 | |
|---|
| 133 | **lineWidth** |
|---|
| 134 | Sets the width of both axes. |
|---|
| 135 | |
|---|
| 136 | ``float, default = 1.0`` |
|---|
| 137 | |
|---|
| 138 | **lineColor** |
|---|
| 139 | Sets the color of both axes. |
|---|
| 140 | |
|---|
| 141 | ``hexadecimal color code, default = '#0f0000'`` |
|---|
| 142 | |
|---|
| 143 | **tickSize** |
|---|
| 144 | Sets the tick size of both axes. |
|---|
| 145 | |
|---|
| 146 | ``float, default = 3.0`` |
|---|
| 147 | |
|---|
| 148 | **labelColor** |
|---|
| 149 | Sets the color of the labels of both axes. |
|---|
| 150 | |
|---|
| 151 | ``hexadecimal color code, default = '#666666'`` |
|---|
| 152 | |
|---|
| 153 | **labelFont** |
|---|
| 154 | Sets the font of the labels of both axes. |
|---|
| 155 | |
|---|
| 156 | ``font name, default = 'Tahoma'`` |
|---|
| 157 | |
|---|
| 158 | **labelFontSize** |
|---|
| 159 | Sets the font size of the labels of both axes. |
|---|
| 160 | |
|---|
| 161 | ``integer, default = 9`` |
|---|
| 162 | |
|---|
| 163 | **labelWidth** |
|---|
| 164 | Sets the width of the labels of both axes. |
|---|
| 165 | |
|---|
| 166 | ``float, default = 50.0`` |
|---|
| 167 | |
|---|
| 168 | .. _x-axis-options: |
|---|
| 169 | |
|---|
| 170 | X-Axis Options |
|---|
| 171 | ^^^^^^^^^^^^^^ |
|---|
| 172 | |
|---|
| 173 | **hide** |
|---|
| 174 | Toggles x-axis visibility. |
|---|
| 175 | |
|---|
| 176 | ``boolean, default = False`` |
|---|
| 177 | |
|---|
| 178 | .. _xticks: |
|---|
| 179 | |
|---|
| 180 | **ticks** |
|---|
| 181 | Sets the tick labels for the x-axis. The format is: |
|---|
| 182 | |
|---|
| 183 | ``[{'v': x, 'label': m}, {'v': x+1, 'label': n}]`` |
|---|
| 184 | |
|---|
| 185 | where x is the index (starting from 0) and m and n are the tick labels. |
|---|
| 186 | |
|---|
| 187 | If your data is in the form: |
|---|
| 188 | |
|---|
| 189 | Rain = ( |
|---|
| 190 | ('Jan', 32.7), |
|---|
| 191 | ('Feb', 9.5), |
|---|
| 192 | ('Mar', 25.5), |
|---|
| 193 | ('Apr', 13.7), |
|---|
| 194 | ('May', 41.5), |
|---|
| 195 | ('Jun', 782.2), |
|---|
| 196 | ) |
|---|
| 197 | |
|---|
| 198 | and it is imported as Rain, then you can generate the ticks using: |
|---|
| 199 | |
|---|
| 200 | 'ticks': [dict(v=i, label=l[0]) for i, l in enumerate(Rain)], |
|---|
| 201 | |
|---|
| 202 | ``list of dictionaries, default = None`` |
|---|
| 203 | |
|---|
| 204 | **tickCount** |
|---|
| 205 | Sets the number of ticks on the x-axis. |
|---|
| 206 | |
|---|
| 207 | ``integer, default = 10`` |
|---|
| 208 | |
|---|
| 209 | **tickPrecision** |
|---|
| 210 | Sets the precision (number of decimal places) of ticks on the x-axis. |
|---|
| 211 | |
|---|
| 212 | ``integer, default = 1`` |
|---|
| 213 | |
|---|
| 214 | **range** |
|---|
| 215 | Sets the range for the x-axis. For example, if you want to show 3 bars on a |
|---|
| 216 | chart big enough for 6 bars: |
|---|
| 217 | |
|---|
| 218 | ``range = (0.0, 5.0)`` |
|---|
| 219 | |
|---|
| 220 | ``float, default = None`` |
|---|
| 221 | |
|---|
| 222 | **rotate** |
|---|
| 223 | Sets the rotation angle of the x-axis ticks. |
|---|
| 224 | |
|---|
| 225 | ``degrees, default = None`` |
|---|
| 226 | |
|---|
| 227 | **label** |
|---|
| 228 | Sets the x-axis label. |
|---|
| 229 | |
|---|
| 230 | ``string, default = None`` |
|---|
| 231 | |
|---|
| 232 | .. _y-axis-options: |
|---|
| 233 | |
|---|
| 234 | Y-Axis Options |
|---|
| 235 | ^^^^^^^^^^^^^^ |
|---|
| 236 | |
|---|
| 237 | **hide** |
|---|
| 238 | Toggles y-axis visibility. |
|---|
| 239 | |
|---|
| 240 | ``boolean, default = False`` |
|---|
| 241 | |
|---|
| 242 | **ticks** |
|---|
| 243 | |
|---|
| 244 | ``list of dictionaries, default = None`` |
|---|
| 245 | |
|---|
| 246 | **tickCount** |
|---|
| 247 | Sets the number of ticks on the y-axis. |
|---|
| 248 | |
|---|
| 249 | ``integer, default = 10`` |
|---|
| 250 | |
|---|
| 251 | **tickPrecision** |
|---|
| 252 | Sets the precision (number of decimal places) of ticks on the y-axis. |
|---|
| 253 | |
|---|
| 254 | ``integer, default = 1`` |
|---|
| 255 | |
|---|
| 256 | **range** |
|---|
| 257 | Sets the range for the y-axis. For example, if you want to leave some room at |
|---|
| 258 | the top of your chart: |
|---|
| 259 | |
|---|
| 260 | ``range = (0.0, ymax+(ymax/3.0))`` |
|---|
| 261 | |
|---|
| 262 | where ``ymax`` is the maximum y value. The above will leave 1/3 of the chart |
|---|
| 263 | empty at the top. |
|---|
| 264 | |
|---|
| 265 | ``float, default = None`` |
|---|
| 266 | |
|---|
| 267 | **rotate** |
|---|
| 268 | Sets the rotation angle of the y-axis ticks. |
|---|
| 269 | |
|---|
| 270 | ``degrees, default = None`` |
|---|
| 271 | |
|---|
| 272 | **label** |
|---|
| 273 | Sets the y-axis label. |
|---|
| 274 | |
|---|
| 275 | ``string, default = None`` |
|---|
| 276 | |
|---|
| 277 | Background Options |
|---|
| 278 | ------------------ |
|---|
| 279 | |
|---|
| 280 | **hide** |
|---|
| 281 | Toggles the visibility of the background. |
|---|
| 282 | |
|---|
| 283 | ``boolean, default = False`` |
|---|
| 284 | |
|---|
| 285 | **baseColor** |
|---|
| 286 | Sets the color of the area around the chart. It's the background color for |
|---|
| 287 | the ticks and labels. |
|---|
| 288 | |
|---|
| 289 | ``hexadecimal color code, default = None`` |
|---|
| 290 | |
|---|
| 291 | **chartColor** |
|---|
| 292 | Sets the color of the chart. |
|---|
| 293 | |
|---|
| 294 | ``hexadecimal color code, default = '#f5f5f5'`` |
|---|
| 295 | |
|---|
| 296 | **lineColor** |
|---|
| 297 | Sets the color of the chart line. |
|---|
| 298 | |
|---|
| 299 | ``hexadecimal color code, default = '#ffffff'`` |
|---|
| 300 | |
|---|
| 301 | **lineWidth** |
|---|
| 302 | Sets the width of the chart line. |
|---|
| 303 | |
|---|
| 304 | ``float, default = 1.5`` |
|---|
| 305 | |
|---|
| 306 | .. index:: legend options |
|---|
| 307 | .. _legend-options: |
|---|
| 308 | |
|---|
| 309 | Legend Options |
|---|
| 310 | -------------- |
|---|
| 311 | |
|---|
| 312 | **opacity** |
|---|
| 313 | Sets the opacity of the legend. The value ranges from 0 to 1.0. |
|---|
| 314 | |
|---|
| 315 | ``float, default = 0.8`` |
|---|
| 316 | |
|---|
| 317 | **borderColor** |
|---|
| 318 | Sets the border color of the legend. |
|---|
| 319 | |
|---|
| 320 | ``hexadecimal color code, default = '#000000'`` |
|---|
| 321 | |
|---|
| 322 | **hide** |
|---|
| 323 | Toggles the visibility of the legend. |
|---|
| 324 | |
|---|
| 325 | ``boolean, default = False`` |
|---|
| 326 | |
|---|
| 327 | **position** |
|---|
| 328 | This option can be used to place the legend at a particular location on the |
|---|
| 329 | chart. The top, bottom, left, and right offsets can be adjusted. |
|---|
| 330 | |
|---|
| 331 | ``int, default = top: 20, left: 40, bottom: None, right: None`` |
|---|
| 332 | |
|---|
| 333 | .. index:: padding options |
|---|
| 334 | .. _padding-options: |
|---|
| 335 | |
|---|
| 336 | Padding Options |
|---|
| 337 | --------------- |
|---|
| 338 | |
|---|
| 339 | **left** |
|---|
| 340 | Sets the left padding for the chart. |
|---|
| 341 | |
|---|
| 342 | ``int, default = 30`` |
|---|
| 343 | |
|---|
| 344 | **right** |
|---|
| 345 | Sets the right padding for the chart. |
|---|
| 346 | |
|---|
| 347 | ``int, default = 30`` |
|---|
| 348 | |
|---|
| 349 | **top** |
|---|
| 350 | Sets the top padding for the chart. |
|---|
| 351 | |
|---|
| 352 | ``int, default = 30`` |
|---|
| 353 | |
|---|
| 354 | **bottom** |
|---|
| 355 | Sets the bottom padding for the chart. |
|---|
| 356 | |
|---|
| 357 | ``int, default = 30`` |
|---|
| 358 | |
|---|
| 359 | .. index:: stroke options |
|---|
| 360 | .. _stroke-options: |
|---|
| 361 | |
|---|
| 362 | Stroke Options |
|---|
| 363 | -------------- |
|---|
| 364 | |
|---|
| 365 | **color** |
|---|
| 366 | Sets the color of the bar outline stroke. |
|---|
| 367 | |
|---|
| 368 | ``hexadecimal color code, default = '#ffffff'`` |
|---|
| 369 | |
|---|
| 370 | **hide** |
|---|
| 371 | Toggles the visibility of the bar outline stroke. |
|---|
| 372 | |
|---|
| 373 | ``boolean, default = False`` |
|---|
| 374 | |
|---|
| 375 | **shadow** |
|---|
| 376 | Toggles the visibility of a shadow around each bar. |
|---|
| 377 | |
|---|
| 378 | ``boolean, default = True`` |
|---|
| 379 | |
|---|
| 380 | **width** |
|---|
| 381 | Sets the width of the bar outline stroke. |
|---|
| 382 | |
|---|
| 383 | ``int, default = 2`` |
|---|
| 384 | |
|---|
| 385 | .. index:: yval options |
|---|
| 386 | .. _yval-options: |
|---|
| 387 | |
|---|
| 388 | Yval Options |
|---|
| 389 | ------------ |
|---|
| 390 | |
|---|
| 391 | .. versionadded:: 0.4.2 |
|---|
| 392 | |
|---|
| 393 | **show** |
|---|
| 394 | Toggles the visibility of y values above the bars. |
|---|
| 395 | |
|---|
| 396 | ``boolean, default = False`` |
|---|
| 397 | |
|---|
| 398 | **inside** |
|---|
| 399 | Toggles the placement of the y values. They are above the bars by default. If |
|---|
| 400 | a bar is too small to show its y value inside the bar, the value is drawn above |
|---|
| 401 | the bar. |
|---|
| 402 | |
|---|
| 403 | ``boolean, default = False`` |
|---|
| 404 | |
|---|
| 405 | **fontSize** |
|---|
| 406 | Sets the font size of the y values. |
|---|
| 407 | |
|---|
| 408 | ``int, default = 11`` |
|---|
| 409 | |
|---|
| 410 | **fontColor** |
|---|
| 411 | Sets the color of the font of the y values. |
|---|
| 412 | |
|---|
| 413 | ``hexadecimal color code, default = '#000000'`` |
|---|
| 414 | |
|---|
| 415 | .. index:: miscellaneous options |
|---|
| 416 | .. _misc-options: |
|---|
| 417 | |
|---|
| 418 | Miscellaneous Options |
|---|
| 419 | --------------------- |
|---|
| 420 | |
|---|
| 421 | **fillOpacity** |
|---|
| 422 | Sets the opacity of the bars. |
|---|
| 423 | |
|---|
| 424 | ``float, default = 1.0`` |
|---|
| 425 | |
|---|
| 426 | **shouldFill** |
|---|
| 427 | Toggles whether the bars should be filled. |
|---|
| 428 | |
|---|
| 429 | ``boolean, default = True`` |
|---|
| 430 | |
|---|
| 431 | **barWidthFillFraction** |
|---|
| 432 | Sets the fraction of the width that will be used to draw the bar. For example, |
|---|
| 433 | a fraction of 1.0 will use the whole width to draw the bars (the bars will touch). |
|---|
| 434 | |
|---|
| 435 | ``float, default = 0.75`` |
|---|
| 436 | |
|---|
| 437 | **pieRadius** |
|---|
| 438 | Sets the radius of the pie chart. This option is ignored for other charts. |
|---|
| 439 | |
|---|
| 440 | ``float, default = 0.4`` |
|---|
| 441 | |
|---|
| 442 | **colorScheme** |
|---|
| 443 | Sets the color scheme of the chart. Available schemes include |
|---|
| 444 | red, green, blue, grey, black, and darkcyan. DEFAULT_COLOR is |
|---|
| 445 | '#3c581a' (green). |
|---|
| 446 | |
|---|
| 447 | ``hexadecimal color code, default = DEFAULT_COLOR`` |
|---|
| 448 | |
|---|
| 449 | **title** |
|---|
| 450 | Sets the title of the chart. |
|---|
| 451 | |
|---|
| 452 | ``string, default = None`` |
|---|
| 453 | |
|---|
| 454 | **titleFont** |
|---|
| 455 | Sets the font of the chart title. |
|---|
| 456 | |
|---|
| 457 | ``font name, default = 'Tahoma'`` |
|---|
| 458 | |
|---|
| 459 | **titleFontSize** |
|---|
| 460 | Sets the size of the chart title font. |
|---|
| 461 | |
|---|
| 462 | ``int, default = 12`` |
|---|
| 463 | |
|---|