Many properties of graphs in PyCha can be easily customized. Options include colors, font sizes, widths, placements, and opacity. You can get a feel for what the options do with Chavier (frontend gui for PyCha).
The default options are:
DEFAULT_OPTIONS = Option(
axis=Option(
lineWidth=1.0,
lineColor='#0f0000',
tickSize=3.0,
labelColor='#666666',
labelFont='Tahoma',
labelFontSize=9,
labelWidth=50.0,
tickFont='Tahoma',
tickFontSize=9,
x=Option(
hide=False,
ticks=None,
tickCount=10,
tickPrecision=1,
range=None,
rotate=None,
label=None,
interval=0,
),
y=Option(
hide=False,
ticks=None,
tickCount=10,
tickPrecision=1,
range=None,
rotate=None,
label=None,
interval=0,
),
),
background=Option(
hide=False,
baseColor=None,
chartColor='#f5f5f5',
lineColor='#ffffff',
lineWidth=1.5,
),
legend=Option(
opacity=0.8,
borderColor='#000000',
hide=False,
position=Option(top=20, left=40, bottom=None, right=None),
),
padding=Option(
left=30,
right=30,
top=30,
bottom=30,
),
stroke=Option(
color='#ffffff',
hide=False,
shadow=True,
width=2
),
yvals=Option(
show=False,
inside=False,
fontSize=11,
fontColor='#000000',
),
fillOpacity=1.0,
shouldFill=True,
barWidthFillFraction=0.75,
pieRadius=0.4,
colorScheme=Option(
name='gradient',
args=Option(
initialColor=DEFAULT_COLOR,
colors=None,
),
),
title=None,
titleFont='Tahoma',
titleFontSize=12,
)
The default options can be changed using a Python dictionary (options = {}). A typical user option dictionary looks like:
options = {
'axis': {
'x': {
'ticks': [dict(v=i, label=l[0]) for i, l in enumerate(Tainan)],
'label': 'Month',
'rotate': 25,
},
'y': {
'tickCount': 4,
'rotate': 25,
'label': 'Precipitation (mm)'
}
},
'background': {
'chartColor': '#d8e7ec',
'baseColor': '#efebe7',
'lineColor': '#444444'
},
'colorScheme': '#6eafc1',
'legend': {
'hide': False,
'position': {'top': 5, 'left': 5},
},
'padding': {
'left': 135,
'bottom': 55,
},
'stroke': {'hide': True},
'title': 'Monthly Precipitation'
}
Sets the width of both axes.
float, default = 1.0
Sets the color of both axes.
hexadecimal color code, default = '#0f0000'
Sets the tick size of both axes.
float, default = 3.0
Sets the color of the labels of both axes.
hexadecimal color code, default = '#666666'
Sets the font of the labels of both axes.
font name, default = 'Tahoma'
Sets the font size of the labels of both axes.
integer, default = 9
Sets the width of the labels of both axes.
float, default = 50.0
New in version 0.5.0.
Sets the font of the ticks of both axes.
font name, default = 'Tahoma'
New in version 0.5.0.
Sets the size of the font of the ticks of both axes.
integer, default = 9
Toggles x-axis visibility.
boolean, default = False
Sets the tick labels for the x-axis. The format is:
[{'v': x, 'label': m}, {'v': x+1, 'label': n}]
where x is the index (starting from 0) and m and n are the tick labels.
If your data is in the form:
Rain = ( (‘Jan’, 32.7), (‘Feb’, 9.5), (‘Mar’, 25.5), (‘Apr’, 13.7), (‘May’, 41.5), (‘Jun’, 782.2), )
and it is imported as Rain, then you can generate the ticks using:
‘ticks’: [dict(v=i, label=l[0]) for i, l in enumerate(Rain)],
list of dictionaries, default = None
Sets the number of ticks on the x-axis.
integer, default = 10
Sets the precision (number of decimal places) of ticks on the x-axis.
integer, default = 1
Sets the range for the x-axis. For example, if you want to show 3 bars on a chart big enough for 6 bars:
range = (0.0, 5.0)
float, default = None
Sets the rotation angle of the x-axis ticks.
degrees, default = None
Sets the x-axis label.
string, default = None
New in version 0.5.0.
Sets the interval of the ticks on the x-axis. The option default is 0, which means that it is not used.
Note
The ticks, interval, and tickCount options are mutually exclusive; you can only use one of them at a time. If you set two or more of these options, their priority is as follows:
- ticks
- interval
- tickCount
integer, default = 0
Toggles y-axis visibility.
boolean, default = False
ticks
list of dictionaries, default = None
Sets the number of ticks on the y-axis.
integer, default = 10
Sets the precision (number of decimal places) of ticks on the y-axis.
integer, default = 1
Sets the range for the y-axis. For example, if you want to leave some room at the top of your chart:
range = (0.0, ymax+(ymax/3.0))
where ymax is the maximum y value. The above will leave 1/3 of the chart empty at the top.
float, default = None
Sets the rotation angle of the y-axis ticks.
degrees, default = None
Sets the y-axis label.
string, default = None
Sets the interval of the ticks on the y-axis. The option default is 0, which means that it is not used.
Note
The ticks, interval, and tickCount options are mutually exclusive; you can only use one of them at a time. If you set two or more of these options, their priority is as follows:
- ticks
- interval
- tickCount
integer, default = 0
Toggles the visibility of the background.
boolean, default = False
Sets the color of the area around the chart. It’s the background color for the ticks and labels.
hexadecimal color code, default = None
Sets the color of the chart.
hexadecimal color code, default = '#f5f5f5'
Sets the color of the chart line.
hexadecimal color code, default = '#ffffff'
Sets the width of the chart line.
float, default = 1.5
Sets the opacity of the legend. The value ranges from 0 to 1.0.
float, default = 0.8
Sets the border color of the legend.
hexadecimal color code, default = '#000000'
Toggles the visibility of the legend.
boolean, default = False
This option can be used to place the legend at a particular location on the chart. The top, bottom, left, and right offsets can be adjusted.
int, default = top: 20, left: 40, bottom: None, right: None
Sets the left padding for the chart.
int, default = 30
Sets the right padding for the chart.
int, default = 30
Sets the top padding for the chart.
int, default = 30
Sets the bottom padding for the chart.
int, default = 30
Sets the color of the bar outline stroke.
hexadecimal color code, default = '#ffffff'
Toggles the visibility of the bar outline stroke.
boolean, default = False
Toggles the visibility of a shadow around each bar.
boolean, default = True
Sets the width of the bar outline stroke.
int, default = 2
New in version 0.4.2.
Toggles the visibility of y values above the bars.
boolean, default = False
Toggles the placement of the y values. They are above the bars by default. If a bar is too small to show its y value inside the bar, the value is drawn above the bar.
boolean, default = False
Sets the font size of the y values.
int, default = 11
Sets the color of the font of the y values.
hexadecimal color code, default = '#000000'
Sets the opacity of the bars.
float, default = 1.0
Toggles whether the bars should be filled.
boolean, default = True
Sets the fraction of the width that will be used to draw the bar. For example, a fraction of 1.0 will use the whole width to draw the bars (the bars will touch).
float, default = 0.75
Sets the radius of the pie chart. This option is ignored for other charts.
float, default = 0.4
Sets the color scheme of the chart. Available schemes include red, green, blue, grey, black, and darkcyan. DEFAULT_COLOR is ‘#3c581a’ (green).
New in version 0.5.0.
In the pycha.color module, there is a class called ColorScheme. Every subclass of this class is registered in a special registry and available in the chart options under the key colorScheme.name. Pycha now provides three different color schemes but users can write as many as they want. The three color schemes are:
- Gradient: for old nice pycha colors
- Fixed: for fixed user specified colors
- Rainbow: for rainbow colors
You can use these schemes by putting their lowercase names in the key mentioned above. For example, to use the Rainbow color scheme, your options should look like:
options = {
'colorScheme': {
'name': 'rainbow',
},
}
If the color scheme needs additional arguments, you should put them in the colorScheme.args option. For example, the Fixed color scheme needs a list with the colors for each dataset:
options = {
'colorScheme': {
'name': 'fixed',
'args': {
'colors': ['#ff0000', '#00ff00'],
},
},
}
Please check the docstring of each Color Scheme subclass to learn about its optional and mandatory arguments.
Warning
This feature introduces a backwards imcompatible change because until Pycha 0.4.2, the option colorScheme was a string and not a dictionary. That string was the initial color used in the old gradient color scheme used by Pycha. You can either remove the key from your options and still get the gradient since it’s the default color scheme in Pycha, or update the options like this:
options = {
'colorScheme': {
'name': 'gradient',
'args': {
'initialColor': your_color_here,
},
},
}
hexadecimal color code, default = DEFAULT_COLOR
Sets the title of the chart.
string, default = None
Sets the font of the chart title.
font name, default = 'Tahoma'
Sets the size of the chart title font.
int, default = 12