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: object

Main 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()

__add__(other)[source]

Add layers, themes, scales etc using + operator

coord_equal(**kwargs)[source]

Apply equal aspect ratio coordinate system

coord_fixed(ratio=1, **kwargs)[source]

Apply fixed aspect ratio coordinate system

coord_flip(**kwargs)[source]

Apply coordinate flip

coord_trans(x='identity', y='identity', **kwargs)[source]

Apply coordinate transformation

facet_grid(facets, **kwargs)[source]

Apply facet grid

facet_wrap(facets, **kwargs)[source]

Apply facet wrap

geom_area(mapping=None, **kwargs)[source]

Add area plot to the plot

geom_bar(mapping=None, **kwargs)[source]

Add bars to the plot

geom_boxplot(mapping=None, **kwargs)[source]

Add box plots to the plot

geom_density(mapping=None, **kwargs)[source]

Add density plots to the plot

geom_errorbar(mapping=None, **kwargs)[source]

Add error bars to the plot

geom_histogram(mapping=None, **kwargs)[source]

Add histogram to the plot

geom_label(mapping=None, **kwargs)[source]

Add text labels with background to the plot

geom_line(mapping=None, **kwargs)[source]

Add lines to the plot

geom_map(mapping=None, **kwargs)[source]

Add geographic map to the plot

geom_point(mapping=None, **kwargs)[source]

Add points to the plot

geom_raster(mapping=None, **kwargs)[source]

Add raster/image tiles to the plot

geom_ribbon(mapping=None, **kwargs)[source]

Add ribbon plot to the plot

geom_smooth(mapping=None, **kwargs)[source]

Add smoothed line to the plot

geom_text(mapping=None, **kwargs)[source]

Add text annotations to the plot

geom_tile(mapping=None, **kwargs)[source]

Add rectangular tiles to the plot

geom_violin(mapping=None, **kwargs)[source]

Add violin plot to the plot

labs(title=None, x=None, y=None, **kwargs)[source]

Add labels to the plot

scale_color_brewer(**kwargs)[source]

Add ColorBrewer color scale (American spelling)

scale_color_continuous(**kwargs)[source]

Apply continuous color scale

scale_color_discrete(**kwargs)[source]

Apply discrete color scale

scale_color_manual(**kwargs)[source]

Apply manual color scale

scale_color_viridis_c(**kwargs)[source]

Apply continuous viridis color scale (American spelling)

scale_color_viridis_d(**kwargs)[source]

Apply discrete viridis color scale (American spelling)

scale_colour_brewer(**kwargs)[source]

Add ColorBrewer color scale

scale_colour_fill_viridis_d(**kwargs)[source]

Apply discrete viridis fill scale (British spelling)

scale_colour_viridis_c(**kwargs)[source]

Apply continuous viridis color scale

scale_colour_viridis_d(**kwargs)[source]

Apply discrete viridis color scale

scale_fill_brewer(**kwargs)[source]

Add ColorBrewer fill scale

scale_fill_viridis_c(**kwargs)[source]

Apply continuous viridis fill scale

scale_fill_viridis_d(**kwargs)[source]

Apply discrete viridis fill scale

show()[source]

Display the plot

theme(**kwargs)[source]

Apply advanced theme with element-level control

theme_bw(**kwargs)[source]

Apply black and white theme

theme_classic(**kwargs)[source]

Apply classic theme

theme_dark(**kwargs)[source]

Apply dark theme

theme_minimal(**kwargs)[source]

Apply minimal theme

xlim(*args)[source]

Set x-axis limits

ylim(*args)[source]

Set y-axis limits

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: object

Aesthetic 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: object

Base 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:

list

Example

c(1, 2, 3) # Returns [1, 2, 3] c(‘a’, ‘b’, ‘c’) # Returns [‘a’, ‘b’, ‘c’]

class ggviews.utils.coord_flip[source]

Bases: UtilityLayer

Flip 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:

pandas.Categorical

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: UtilityLayer

Add 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:

list

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:

list

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: UtilityLayer

Set 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: UtilityLayer

Set 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))