Core API¶
The core module contains the fundamental classes for creating ggplot-style visualizations.
ggplot¶
- class ggviews.core.ggplot(data=None, mapping=None)[source]¶
Bases:
objectMain ggplot class for creating grammar of graphics plots
This is the entry point for all ggplot-style visualizations. Use method chaining to build up your plot layer by layer.
- Parameters:
data – pandas DataFrame containing the data to plot
mapping – aes object defining default aesthetic mappings
Example
ggplot(df, aes(x=’x’, y=’y’)).geom_point()
aes (Aesthetics)¶
- class ggviews.core.aes(x=None, y=None, color=None, colour=None, size=None, alpha=None, shape=None, fill=None, linetype=None, **kwargs)[source]¶
Bases:
objectAesthetic mappings for ggplot
Maps data variables to visual properties like x, y, color, size, etc.
- Parameters:
x – Variable for x-axis
y – Variable for y-axis
color – Variable for color mapping
colour – Alias for color (British spelling)
size – Variable for size mapping
alpha – Variable for alpha/transparency mapping
shape – Variable for shape mapping
fill – Variable for fill color mapping
linetype – Variable for line type mapping
**kwargs – Additional aesthetic mappings
Utility Functions¶
Utility functions for ggviews
This module contains helper functions and utilities used throughout ggviews.
- class ggviews.utils.UtilityLayer(**kwargs)[source]¶
Bases:
objectBase class for utility layers like labs, xlim, ylim
- ggviews.utils.c(*args)[source]¶
Combine values into a list (R-style c() function)
- Parameters:
*args – Values to combine
- Returns:
Combined values
- Return type:
Example
c(1, 2, 3) # Returns [1, 2, 3] c(‘a’, ‘b’, ‘c’) # Returns [‘a’, ‘b’, ‘c’]
- class ggviews.utils.coord_flip[source]¶
Bases:
UtilityLayerFlip the coordinate system
Swaps the x and y axes. Useful for creating horizontal bar charts from vertical ones.
Example
ggplot(df, aes(x=’category’, y=’value’)).geom_bar() + coord_flip()
- ggviews.utils.cut(x, breaks, labels=None)[source]¶
Cut continuous variable into discrete bins
- Parameters:
x – Continuous values to cut
breaks – Break points or number of breaks
labels – Labels for the bins
- Returns:
Binned values
- Return type:
Example
cut(df[‘age’], breaks=5) cut(df[‘score’], breaks=[0, 50, 80, 100], labels=[‘Low’, ‘Medium’, ‘High’])
- ggviews.utils.expand_limits(**kwargs)[source]¶
Expand the plot limits to include additional values
- Parameters:
x – Expand x-axis to include these values
y – Expand y-axis to include these values
**kwargs – Additional limits to expand
Example
expand_limits(x=0, y=c(0, 100))
- ggviews.utils.guide_colorbar(title=None, **kwargs)[source]¶
Create a colorbar guide
- Parameters:
title – Colorbar title
**kwargs – Additional colorbar parameters
Example
guides(color=guide_colorbar(title=’Value’))
- ggviews.utils.guide_legend(title=None, **kwargs)[source]¶
Create a legend guide
- Parameters:
title – Legend title
**kwargs – Additional legend parameters
Example
guides(color=guide_legend(title=’Species’))
- ggviews.utils.guides(**kwargs)[source]¶
Control legend guides
- Parameters:
color – Control color legend (‘legend’, ‘colorbar’, None)
colour – Alias for color
fill – Control fill legend
size – Control size legend
alpha – Control alpha legend
**kwargs – Additional guide specifications
Example
guides(color=’none’) # Remove color legend guides(fill=guide_legend(title=’Species’))
- class ggviews.utils.labs(title=None, subtitle=None, caption=None, x=None, y=None, color=None, colour=None, fill=None, size=None, alpha=None, **kwargs)[source]¶
Bases:
UtilityLayerAdd labels to plots
Sets axis labels, plot title, subtitle, and caption.
- Parameters:
title – Plot title
subtitle – Plot subtitle
caption – Plot caption
x – X-axis label
y – Y-axis label
color – Legend title for color aesthetic
colour – Alias for color (British spelling)
fill – Legend title for fill aesthetic
size – Legend title for size aesthetic
alpha – Legend title for alpha aesthetic
**kwargs – Additional label mappings
Example
labs(title=”My Plot”, x=”Height”, y=”Weight”, color=”Species”)
- ggviews.utils.rep(x, times)[source]¶
Repeat elements
- Parameters:
x – Value or list to repeat
times – Number of times to repeat
- Returns:
Repeated values
- Return type:
Example
rep(‘a’, 3) # [‘a’, ‘a’, ‘a’] rep([1, 2], 2) # [1, 2, 1, 2]
- ggviews.utils.seq(start, stop, step=1)[source]¶
Generate a sequence of numbers
- Parameters:
start – Starting value
stop – Ending value (inclusive)
step – Step size
- Returns:
Sequence of numbers
- Return type:
Example
seq(1, 10) # [1, 2, 3, …, 10] seq(0, 1, 0.1) # [0, 0.1, 0.2, …, 1.0]
- class ggviews.utils.xlim(*args)[source]¶
Bases:
UtilityLayerSet x-axis limits
- Parameters:
*args – Either (min, max) or a single list/tuple of (min, max)
Examples
xlim(0, 100) xlim([0, 100]) xlim((0, 100))
- class ggviews.utils.ylim(*args)[source]¶
Bases:
UtilityLayerSet y-axis limits
- Parameters:
*args – Either (min, max) or a single list/tuple of (min, max)
Examples
ylim(0, 100) ylim([0, 100]) ylim((0, 100))