• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Data Viz with Python and R

Learn to Make Plots in Python and R

  • Home
  • Python Viz
  • Seaborn
  • Altair
  • R Viz
  • ggplot2
  • About
    • Privacy Policy
  • Show Search
Hide Search

How to Make Horizontal Violin Plot with Seaborn in Python?

datavizpyr · February 14, 2020 ·

In this tutorial, we will learn how to make horizontal violin plot in Seaborn with Python. With Seaborn, we can use two similar functions, catplot() and violinplot() to make violin plots. Making a violinplot horizontal with Seaborn is pretty simple. All we need to do is specify the categorical variable on y-axis and the numerical variable on x-axis with Seaborn functions for making violinplot.

Let us load the packages needed to make horizontal violin plots.

import seaborn as sns 
import matplotlib.pyplot as plt
import pandas as pd

We will use Seattle weather data available from vega-datasets’ github page. We cab directly load the data from the website using Pandas’ read_csv() function.

weather_df = pd.read_csv("https://raw.githubusercontent.com/vega/vega-datasets/master/data/weather.csv")
print(weather_df.head(n=3))

  location        date  precipitation  temp_max  temp_min  wind  weather
0  Seattle  2012-01-01            0.0      12.8       5.0   4.7  drizzle
1  Seattle  2012-01-02           10.9      10.6       2.8   4.5     rain
2  Seattle  2012-01-03            0.8      11.7       7.2   2.3     rain

We will first use Seaborn’ Catplot function to make horizontal violinplot and then use Seaborn’s violinplot() function.

How Make Horizontal Violin Plot with Catplot in Seaborn?

Let us catplot() in Seaborn to make the horizontal violin plot. As catplot() function can be used for number of plot types, we need to use kind=”violin”, after specifying the x and y axis variables.

# horizontal violinplot with catplot seaborn
vio_plot = sns.catplot(x="weather", y="temp_max", kind="violin", aspect=2,data=weather_df)
plt.xlabel("Weather", size=14)
plt.ylabel("Max Temp", size=14)
plt.title("Violin Plot with Seaborn Catplot", size=20)
vio_plot.savefig("Violin_plot_with_catplot_Seaborn_Python.png")

Here we have also customized the figure size with aspect argument and set the axis labels and title.

Horizontal Violin Plot with Catplot Seaborn
Horizontal Violin Plot with Catplot Seaborn

How to Make Horizontal Violin Plot with violinplot in Seaborn ?

We can also make horizontal violin plot using Seaborn’s violinplot() function as follows.

# set figure size
plt.figure(figsize=(10,8))
# horizontal violinplot with catplot seaborn
vio_plot=sns.violinplot(x="weather", y="temp_max", data=weather_df)
plt.xlabel("Weather", size=14)
plt.ylabel("Max Temp", size=14)
plt.title("Violin Plot with Seaborn violinplot()", size=20)
plt.savefig("violin_plot_with_Seaborn_Python.png")
Horizontal Violin Plot with Seaborn violinplot()
Horizontal Violin Plot with Seaborn violinplot()

Related posts:

Grouped Barplot with SeabornHow To Make Grouped Barplots in Python with Seaborn? Seaborn Violinplot with Data Points Using SwarmplotHow To Make Violinpot with data points in Seaborn? Grouped Boxplot with Jittered Data Points SeabornGrouped Boxplot with Jittered Points with Seaborn Python Customize Facetgrid plot titles in Seaborn_PythonHow to Customize Titles in Multi-Panel plots with Seaborn?

Filed Under: Horizontal Violinplot Seaborn, Python, Seaborn Tagged With: Python, Seaborn, Violinplot

Primary Sidebar

Tags

Altair barplot Boxplot boxplot python boxplot with jiitered text labels Bubble Plot Color Palette Countplot Density Plot Facet Plot gganimate ggplot2 ggplot2 Boxplot ggplot2 error ggplot boxplot ggridges ggtext element_markdown() Grouped Barplot R heatmap heatmaps Histogram Histograms Horizontal boxplot Python lollipop plot Maps Matplotlib Pandas patchwork pheatmap Pyhon Python R RColorBrewer reorder boxplot ggplot Ridgeline plot Scatter Plot Scatter Plot Altair Seaborn Seaborn Boxplot Stock Price Over Time Stripplot UpSetR Violinplot Violin Plot World Map ggplot2

Buy Me a Coffee

Copyright © 2025 · Daily Dish Pro on Genesis Framework · WordPress · Log in

Go to mobile version