How to change the figure style to Ticks in Seaborn?


In Seaborn, the "ticks" figure style is a minimalistic style that removes the background grid lines but retains the tick marks on the axes. This style focuses on presenting the data without any distracting elements and is useful when we want a clean and simple look for our plots.

When we set the figure style to "ticks" in Seaborn using the 'sns.set_style()' function, the following changes occur in our plots.

  • Background Grid Lines − The background grid lines are removed, resulting in a blank canvas without any horizontal or vertical lines. This helps to reduce visual clutter and draw attention to the data points.

  • Tick Marks − The tick marks on the x-axis and y-axis are retained. Tick marks indicate the locations along the axes and are used for reference and measurement. They provide a visual guide to the values represented by the plot.

  • Labels and Titles − The x-axis label, y-axis label, and plot title can still be added using the usual Matplotlib commands. They are not affected by the "ticks" figure style.

  • To change the figure style to "ticks" in Seaborn, we can follow the steps below.

Install Seaborn

First we have to install the seaborn library in the python environment using the pip command. The below code can be used for installing the seaborn library.

pip install seaborn

Import the necessary libraries

In our Python script or Jupyter Notebook, we need to import the required libraries namely Seaborn and Matplotlib.pyplot. These libraries provide the functionality to create and customize plots.

import seaborn as sns
import matplotlib.pyplot as plt

Set the figure style

For changing the figure style to "ticks" in Seaborn, we have to use the 'sns.set_style()' function. This function allows us to modify the default styles of Matplotlib to match the chosen Seaborn style. The below line of code, will sets the figure style to "ticks".

sns.set_style("ticks")

Now first let’s create a plot without setting the figure style to ticks. So that the plot will have the grid lines in the output plot.

Creating a scatter plot without setting the figure style to ticks

Here we are creating a scatter plot using the scatterplot() function of the seaborn and setting the figure style to whitegrid with the help of sns.set_style(“whitegrid”). Then in the output plot we can see the grid lines.

Example

import seaborn as sns
import matplotlib.pyplot as plt
sns.set_style("whitegrid")
# Sample data
x = ["A", "B", "C", "D"]
y = [10, 20, 15, 25]
sns.set_style("ticks")
# Create a bar plot
sns.scatterplot(x=x, y=y)
# Set labels and title
Plt.grid = "TRUE"
plt.xlabel("Categories")
plt.ylabel("Values")
plt.title("Scatter plot")
plt.show()

Output

Creating the plot by setting the figure style to ticks

Now we are creating a plot by setting the figure style to ticks by using the sns.set_style(“ticks”). So that in the output plot we can observe, the absence of grid lines.

Example

import seaborn as sns
import matplotlib.pyplot as plt
sns.set_style("ticks")
# Sample data
x = ["A", "B", "C", "D"]
y = [10, 20, 15, 25]
# Create a bar plot
sns.scatterplot(x=x, y=y)
# Set labels and title
plt.xlabel("Categories")
plt.ylabel("Values")
plt.title("Scatter plot")
# Display the plot
plt.show()

Output

Updated on: 02-Aug-2023

327 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements