Introduction to Mark Objects

Mark objects are elements that represent data points in a plot, such as scatter points in a scatter plot or bars in a bar plot. These objects can be customized to enhance the clarity, appearance, and overall aesthetics of your data visualizations. The key properties of mark objects include:

  • Coordinates
  • Color
  • Style
  • Size
  • Text
  • Other relevant attributes

This guide delves deeper into each of these properties.

1. Coordinate Properties

These properties define the position of the mark object on the plot. Coordinates generally correspond to the x and y axes in 2-dimensional graphs, but they can also include additional parameters for multi-dimensional graphs, such as the z-axis for 3-dimensional plots, or hue, col, and row for multi-axis grids like Facet Grids.

Some key coordinate properties are:

  • x: Represents the horizontal position of the mark object.
  • y: Represents the vertical position of the mark object.
  • hue: Used to group variables that will produce points with different colors, adding an additional dimension by using color to represent a categorical variable. This is particularly useful in scatter plots and line plots where differentiating between categories is important.
  • col: Subsets the available data into multiple columns.
  • row: Subsets the available data into multiple rows.

In addition to these basic properties, there are other properties that help keep the plots within specified limits, such as xmin(), ymin(), xmax(), and ymax(). These properties allow you to specify the maximum and minimum limits for the graph’s x and y axes.

Example

Python
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

data = pd.DataFrame({
    'variable_x': np.random.rand(50),
    'variable_y': np.random.rand(50),
    'category': np.random.choice(['A', 'B', 'C'], size=50)
})

sns.scatterplot(data=data, x='variable_x', y='variable_y', hue='category')

plt.title('Geeks for Geeks Scatter Plot', color='green')
plt.xlabel('Variable X', color='green')
plt.ylabel('Variable Y', color='green')

plt.show()

Output

Sample Scatter Plot using Coordinate Properties of Seaborn

2. Colour Properties

Colours cab be used as a powerful visual tool to distinguish between different groups or highlight specific data points. Seaborn provides very vast and versatile colour properties to make plots more informative and visually appealing.

Types of colour properties –

Single colour – This is used to apply same colour to all the available mark objects. These are generally used to create minimalistic looks in the graph. It can be done using the attribute “color”.

sns.scatterplot(data=data, x="variable_x", y="variable_y", color="blue")
plt.show()

Palette – based colouring – Through this we can use the colour palette to assign different colours to different mark points in order to enable easy data interpretation. Seaborn includes several in-built palettes and a user can also create there own custom colour palettes. Some of the in-built colour palettes are – deep, muted, bright, etc. Pre-defined palette can be accessed using the “palette” attribute.

sns.scatterplot(data=data, x="variable_x", y="variable_y", hue="category", palette="viridis")
plt.show()

Custom colour palette can be created using the sns.color_palette command.

custom_palette = sns.color_palette(["#3498db", "#e74c3c", "#2ecc71"])
sns.scatterplot(data=data, x="variable_x", y="variable_y", hue="category", palette=custom_palette)
plt.show()

Hue Mapping – It is used to map different data levels using different colours. Hue mapping can be done using hue parameter. his simplifies the process of distinguishing between groups in a dataset and enhances the visual differentiation of categories.

sns.scatterplot(data=data, x="variable_x", y="variable_y", hue="category")
plt.show()

Some addition colour properties are –

  • fillcolor: In plots like bars or shapes, the fillcolor property specifies the colour used to fill those areas.
  • edgecolor: For mark objects with edges, the edgecolor property defines the colour of the edges surrounding those objects. T
  • alpha: The alpha property controls the transparency level of mark objects. A lower alpha value (closer to 0) makes the objects more transparent, while a higher value (closer to 1) makes them more opaque.
  • fillalpha: In filled areas like bars or shapes, the fillalpha property adjusts the transparency of the filled region.
  • edgealpha: The edgealpha property manages the transparency of edges around mark objects.

Example

Python
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

np.random.seed(0)
data = pd.DataFrame({
    'variable_x': np.random.rand(100),
    'variable_y': np.random.rand(100),
    'category': np.random.choice(['A', 'B', 'C'], size=100)
})

sns.set_palette("husl")

sns.scatterplot(data=data, x='variable_x', y='variable_y', hue='category', style='category', size='category', palette='husl')

plt.title('GFG Plot with Seaborn Color Properties')
plt.xlabel('Variable X')
plt.ylabel('Variable Y')

plt.legend(loc='upper right', title='Category')
plt.show()

Output

Scatter Plot showing some Colour Properties of Seaborn

3. Style Properties

Style properties allows for further customisation of mark objects beyond colours. These style properties are used to modify and customise the graph as per the user’s requirements and to enhance the understanding to the generated graph.

Types of style properties –

Marker Style – This allows to create markers in different shapes which can be useful for distinguishing between categories or emphasising specific data points. Some common marker types includes – “o” for circles, “s” for squares, “^” for triangles. These are generally specified using the “marker” parameter.

sns.scatterplot(data=data, x="variable_x", y="variable_y", style="category", markers=["o", "s", "^"])
plt.show()

Linestyle – It is used to define the pattern of lines connecting data points in line plots. It is generally used for distinguishing between different types of trends or series within the same plot. Some common line styles include solid lines (“-“), dashed lines (“–“), and dotted lines (“-.”).

sns.lineplot(data=data, x="time", y="value", style="category", dashes=[(2, 2), (2, 2), (4, 4)])
plt.show()

Edgecolor – It sets the colour of the edges around markers. This can enhance the visual clarity of markers, especially when they are placed on a complex background.

sns.scatterplot(data=data, x="variable_x", y="variable_y", hue="category", edgecolor="black")
plt.show()

Example

Python
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

np.random.seed(0)
data = pd.DataFrame({
    'variable_x': np.random.rand(50),
    'variable_y': np.random.rand(50),
    'category': np.random.choice(['A', 'B', 'C'], size=50)
})


sns.scatterplot(data=data, x='variable_x', y='variable_y', hue='category', style='category', s=100)

plt.title('GFG Scatter Plot')
plt.xlabel('Variable X')
plt.ylabel('Variable Y')

plt.legend(title='Category', loc='upper right')
plt.show()

Output

Sample Scatter Plot showing Style Properties of Seaborn Library

4. Size Properties

These properties are used to control the size and dimensions of the mark objects present in any data visualisation. These properties allows to control the size, thickness, and visibility of elements and can help the plots to be more appealing.

Types of size properties –

size: The size property can be applied to various mark objects such as points, markers, or lines. It accepts a numerical value representing the size of the objects. It can be used to assign same size to all marker points or different sizes to different marker styles.

sns.scatterplot(data=data, x="variable_x", y="variable_y", size=100)
plt.show()

markersize: It is used for setting the size of markers (points) in plots like scatter plots. Larger values result in larger and more prominent markers.

sns.scatterplot(data=data, x="variable_x", y="variable_y", markersize=10)

linewidth: It determines the thickness of lines in plots such as line plots or bar plots. Larger values result in thicker lines.

sns.lineplot(data=data, x="time", y="value", linewidth=2)

edgewidth: It controls the thickness of edges around mark objects like markers or bars. Larger values result in thicker edges.

sns.scatterplot(data=data, x="variable_x", y="variable_y", markersize=10, edgecolor="black", linewidth=1)

strokesize: It indicates the size of strokes or outlines used in plot elements such as shapes, lines, or text.

plt.text(x_position, y_position, "Text", fontsize=12, fontweight='bold', strokesize=1)

Example

Python
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

np.random.seed(0)
data = pd.DataFrame({
    'categories': ['A', 'B', 'C', 'D'],
    'values': np.random.randint(1, 100, 4),
    'sizes': np.random.randint(100, 500, 4)
})

sns.set(style="whitegrid", palette="Set2")

plt.figure(figsize=(8, 6))
sns.barplot(data=data, x='categories', y='values', hue='categories', palette="Set2",
            dodge=False, linewidth=2.5, edgecolor='black')

plt.title('GFG Plot')
plt.xlabel('Categories')
plt.ylabel('Values')

plt.legend(title='Categories', loc='upper right')
plt.show()

Output:

Sample Plot to show Size Properties of Seaborn


Properties of Mark objects in Python Seaborn

Seaborn is a famous Python library that is used for statistical data visualisation. This library is built on top of matplotlib. With seaborn it is easy to create informative and attractive statistical graphs. Working with Seaborn, it is important to understand the mark object properties. This article will look into different things that make up a mark in Seaborn such as coordinates, colour, style, size, text and other properties.

Similar Reads

Introduction to Mark Objects

Mark objects are elements that represent data points in a plot, such as scatter points in a scatter plot or bars in a bar plot. These objects can be customized to enhance the clarity, appearance, and overall aesthetics of your data visualizations. The key properties of mark objects include:...

5. Text Properties

Text properties play a key role in making the generated graphs legible and understandable. Using these properties, we can customizing labels, titles, annotations, and legend text....