INTRODUCTION TO SEABORN. Skill Enhancement Courses (SEC).
What is seaborn ?. Seaborn is a popular Python library used for data visualization tasks. It is built on top of Matplotlib, enhancing its functionality and providing additional features. Seaborn offers a high-level interface that simplifies the creation of complex visualizations. Seamlessly integrates with pandas data structures, making it easy to visualize data directly from pandas data frames. Seaborn provides built-in themes and color palettes for easy customization of plots, ensuring visually appealing visualizations..
Feature of seaborn. "Seaborn enriches data visualization with its user-friendly interface and extensive functionality.".
Different categories of plot in Seaborn. This plot is used to understand the relation between two variables..
# To install Seaborn, use the following pip command !pip install seaborn.
Different types of plot in Seaborn. A visual representation of data points in a graph, displaying the relationship between two variables through their Cartesian coordinates..
A method for graphically depicting groups of numerical data through quartiles, highlighting the median, and identifying outliers..
import seaborn as sns import matplotlib.pyplot as plt # Create some sample data data = # Create the scatter plot sns.scatterplot( x='x',y='y', hue='group', # Color based on 'group' variable size='size', # Size based on 'size' variable style='group', # Not adding visual difference here, but can be used for markers data=data) # Add title and show the plot plt.title('Sample Scatter Plot with Color, Size, and Labels') plt.xlabel('X-Value') plt.ylabel('Y-Value') plt.show().
BAR PLOT. 02.. import seaborn as sns import matplotlib.pyplot as plt # Create some sample data species = ['Cat', 'Dog', 'Rabbit', 'Bird'] lifespan = [15, 12, 8, 10] # Average lifespan (years) offspring_count = [4, 6, 8, 2] # Average offspring per year data = pd.DataFrame() # Create the bar plot with color, size, and label customization sns.barplot(x='Species',y='Lifespan',hue='Offspring Count',data=data) # Add title, axis labels, and rotate x-axis labels for readability plt.title(Average Lifespan by Species') plt.xlabel('Species') plt.ylabel('Average Lifespan') plt.xticks(rotation=45) # Rotate x-axis labels for better readability plt.show().
HISTOGRAM. 03.. import seaborn as sns import matplotlib.pyplot as plt import numpy as np # Generate random integer data data = np.random.randint(1, 100, size=1000) # Random integers between 1 and 100, with 1000 data points # Create the histogram using Seaborn sns.histplot(data, bins=30, kde=True, color='green') # Add title and axis labels plt.title('Histogram of Random Integer Data') plt.xlabel('Values') plt.ylabel('Frequency') # Show the plot plt.show().
HEATMAP. 04.. import seaborn as sns import matplotlib.pyplot as plt import numpy as np data = np.random.rand(20, 20) # Generating a 20x20 array of random values between 0 and 1 sns.heatmap(data, cmap='viridis’) # Add x-axis and y-axis labels with color plt.xlabel('X-axis', color='blue') plt.ylabel('Y-axis', color='green’) # Add title and show the plot plt.title('Simple Heatmap Example with Large Data') plt.show().
Box plot. 05.. import seaborn as sns # Load the fmri dataset fmri = sns.load_dataset("fmri") # Create a box plot sns.boxplot(x="timepoint", # x-axis represents the "timepoint" y="signal", # y-axis represents the "signal" values data=fmri) # Use data from the fmri dataset data = sns.load_dataset('tips') # create grouped boxplot sns.boxplot(x = data['day'], y = data['total_bill'], hue = data['size'], palette = 'husl').
catplot. 06.. import seaborn as sns exercise = sns.load_dataset("exercise") sns.catplot(x="time",y="pulse",hue="kind",col="diet", data=exercise).
Some more types of plot. Voilin plot. A combination of a box plot and a kernel density plot, providing a visual summary of the distribution of data for different categories..
- Seaborn is a powerful tool for creating visualizations in Python. - It simplifies the process of making graphs, even for beginners. - With Seaborn, you can easily customize the look of your graphs with themes and colors. - It works seamlessly with Pandas DataFrames, making data manipulation and visualization straightforward. - Whether you're a beginner or an expert, Seaborn empowers you to tell compelling stories with your data..
THANK YOU. Stay curious and keep exploring the world of data visualization!.