BarChart()
Documentation for the BarPlotter class
To use BarPlotter, use the following import statement:
The BarPlotter
class is a utility designed to generate customizable bar charts from a pandas DataFrame. It is highly configurable, allowing you to set colors, grid options, and more. This class is intended to be modular and reusable across different applications and strategies.
Constructor Arguments:
Argument
Type
Description
Required
dataframe
pd.DataFrame
The pandas DataFrame containing the data to be plotted. It must contain columns corresponding to the x-axis and y-axis values.
Yes
x_col
str
The column name in the DataFrame to be used for the x-axis (e.g., 'strikePrice').
Yes
y_col
str
The column name in the DataFrame to be used for the y-axis (e.g., 'gammaExposure').
Yes
Example Usage:
Methods in BarPlotter
BarPlotter
validate_data()
validate_data()
Validates that the provided DataFrame contains the required columns (x_col
and y_col
).
Returns:
True
: If the required columns are found.False
: If one or more required columns are missing.
Example:
plot_barchart()
plot_barchart()
Generates and displays a bar chart with customizable options for positive and negative y-values, grid settings, and axis properties. Also allows for the inclusion of an optional line plot over the bars.
Argument
Type
Default Value
Description
dataframe
pd.DataFrame
Required
A pandas DataFrame containing the data to be plotted.
x_col
str
Required
The column name for the x-axis (e.g., 'strikePrice').
y_col
str
Required
The column name for the y-axis (e.g., 'gammaExposure').
figure_size
tuple
(12, 8)
Size of the figure in inches (width, height).
dpi
int
100
Dots per inch (DPI) for the figure resolution.
font_size
int
12
Font size for x and y labels.
bar_width
float
0.8
Width of the bars.
grid
bool
True
Enable or disable the grid.
grid_color
str
'grey'
Color of the grid lines.
grid_line_style
str
'--'
Style of the grid lines (e.g., --
, -
).
grid_line_width
float
0.5
Thickness of the grid lines.
axis_color
str
'black'
Color of the axis lines.
tick_color
str
'black'
Color of the tick marks.
axis_line_width
float
1.0
Width of the axis lines.
x_rotation
int
45
Rotation angle of the x-axis labels.
legend
bool
True
Enable or disable the legend.
title_font_size
int
16
Font size of the chart title.
title_font_color
str
'navy'
Color of the chart title.
xlabel_font_size
int
14
Font size for the x-axis label.
ylabel_font_size
int
14
Font size for the y-axis label.
label_color
str
'purple'
Color of both x and y-axis labels.
positive_color
str
'blue'
Color of the bars for positive y-values (e.g., positive gamma exposure).
negative_color
str
'red'
Color of the bars for negative y-values (e.g., negative gamma exposure).
line_data
dict
None
Optional dictionary with keys as x-values and values as line y-values (for line overlay on the bar chart).
line_color
str
'green'
Color of the line plot data (if provided).
background_color
str
'white'
Background color of the figure.
Returns:
Displays the bar chart using matplotlib.
Example:
confirm_valid_data()
confirm_valid_data()
Confirms that the DataFrame is valid for plotting by calling validate_data()
.
Returns:
True
if the data is valid and contains the required columns.False
if the data is missing the required columns.
Example:
Full Example
Last updated