Advertisement
UF6

CSV Pie Chart

UF6
Oct 10th, 2023
1,204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.65 KB | Source Code | 0 0
  1. import pandas as pd
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4.  
  5. # Replace 'Line Plot.csv' with the actual CSV file path
  6. df = pd.read_csv('Line Plot.csv')
  7.  
  8. # Extract data from the DataFrame
  9. values1 = df['Raw Reads']
  10. values2 = df['Trimmed Reads']
  11. values3 = df['Aligned Reads']
  12. values4 = df['Deduplicated Reads']
  13. values5 = df['Stitched Reads']
  14.  
  15. # Combine the data into a list of lists
  16. data = [values1, values2, values3, values4, values5]
  17.  
  18. # Apply a log10 transformation to all data points
  19. data_log10 = [np.log10(data_point) for data_point in data]
  20.  
  21. # Define custom colors for each violin
  22. colors = ['skyblue', 'lightcoral', 'lightgreen', 'orange', 'lightseagreen']
  23.  
  24. # Set the figure size (optional)
  25. plt.figure(figsize=(12, 6))
  26.  
  27. # Create a ViolinPlot object
  28. vp = plt.violinplot(data_log10, showmedians=True, vert=False, widths=0.8)
  29.  
  30. # Customize the violin plot
  31. for i, body in enumerate(vp['bodies']):
  32.     body.set_facecolor(colors[i])
  33.     body.set_edgecolor('black')
  34.     body.set_alpha(0.7)
  35.  
  36. # Add labels to the medians
  37. medians = [median.get_xdata().mean() for median in vp['cmedians']]
  38. for i, median in enumerate(vp['cmedians']):
  39.     median.set_label(f'Median {i + 1}')
  40.     plt.text(median.get_xdata().mean(), i, f'{medians[i]:.2f}', horizontalalignment='center', verticalalignment='bottom')
  41.  
  42. # Add a legend
  43. plt.legend()
  44.  
  45. # Set y-axis labels
  46. plt.yticks(np.arange(1, 6), ['Raw Reads', 'Trimmed Reads', 'Aligned Reads', 'Deduplicated Reads', 'Stitched Reads'])
  47. plt.ylabel('Read Types')
  48.  
  49. # Customize the plot
  50. plt.title('Violin Plot of Reads (log10 scale)')
  51. plt.xlabel('Reads (log10 scale)')
  52.  
  53. # Show the plot
  54. plt.tight_layout()
  55. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement