Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import matplotlib.pyplot as plt
- import numpy as np
- # Replace 'Line Plot.csv' with the actual CSV file path
- df = pd.read_csv('Line Plot.csv')
- # Extract data from the DataFrame
- values1 = df['Raw Reads']
- values2 = df['Trimmed Reads']
- values3 = df['Aligned Reads']
- values4 = df['Deduplicated Reads']
- values5 = df['Stitched Reads']
- # Combine the data into a list of lists
- data = [values1, values2, values3, values4, values5]
- # Apply a log10 transformation to all data points
- data_log10 = [np.log10(data_point) for data_point in data]
- # Define custom colors for each violin
- colors = ['skyblue', 'lightcoral', 'lightgreen', 'orange', 'lightseagreen']
- # Set the figure size (optional)
- plt.figure(figsize=(12, 6))
- # Create a ViolinPlot object
- vp = plt.violinplot(data_log10, showmedians=True, vert=False, widths=0.8)
- # Customize the violin plot
- for i, body in enumerate(vp['bodies']):
- body.set_facecolor(colors[i])
- body.set_edgecolor('black')
- body.set_alpha(0.7)
- # Add labels to the medians
- medians = [median.get_xdata().mean() for median in vp['cmedians']]
- for i, median in enumerate(vp['cmedians']):
- median.set_label(f'Median {i + 1}')
- plt.text(median.get_xdata().mean(), i, f'{medians[i]:.2f}', horizontalalignment='center', verticalalignment='bottom')
- # Add a legend
- plt.legend()
- # Set y-axis labels
- plt.yticks(np.arange(1, 6), ['Raw Reads', 'Trimmed Reads', 'Aligned Reads', 'Deduplicated Reads', 'Stitched Reads'])
- plt.ylabel('Read Types')
- # Customize the plot
- plt.title('Violin Plot of Reads (log10 scale)')
- plt.xlabel('Reads (log10 scale)')
- # Show the plot
- plt.tight_layout()
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement