Violin Plots in Python - tannerjared/MRI_Guide GitHub Wiki

import seaborn as sns

import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

Then import a csv file

df = pd.read_csv(r'/path/to/data/file.csv')

Convert a column to float

df = df.explode("BNM_ACC") #This is a variable of interest

df["BNM_ACC"] = df["BNM_ACC"].astype("float")

Create the violin plots with an overlayed swarm plot.

sns.set_context("talk", font_scale=1.1)

plt.figure(figsize=(10,10))

sns.violinplot(y="BNM_ACC", x="MCI", data=df)

sns.swarmplot(y="BNM_ACC", x="MCI", data=df, color="white", edgecolor="gray")

plt.xlabel("Group")

plt.ylabel("BNM - ACC Functional Connectivity")

plt.show()

#Can save plots like this

plt.savefig("Violinplot_BNM-ACC_MCI_swarmplot.png", format='png',dpi=300)

⚠️ **GitHub.com Fallback** ⚠️