Advertisement
UF6

Updated Pie Chart

UF6
Oct 10th, 2023
1,295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.62 KB | Source Code | 0 0
  1. import pandas as pd
  2. import matplotlib.pyplot as plt
  3.  
  4. # Replace 'Line Plot.csv' with the actual CSV file path
  5. df = pd.read_csv('Line Plot.csv')
  6.  
  7. # Extract data from the DataFrame
  8. values1 = df['Raw Reads']
  9. values2 = df['Trimmed Reads']
  10. values3 = df['Aligned Reads']
  11. values4 = df['Deduplicated Reads']
  12. values5 = df['Stitched Reads']
  13.  
  14. # Calculate the total sum of values for each read type
  15. total_values1 = values1.sum()
  16. total_values2 = values2.sum()
  17. total_values3 = values3.sum()
  18. total_values4 = values4.sum()
  19. total_values5 = values5.sum()
  20.  
  21. # Data for the pie chart
  22. data = [total_values1, total_values2, total_values3, total_values4, total_values5]
  23. labels = ['Raw Reads', 'Trimmed Reads', 'Aligned Reads', 'Deduplicated Reads', 'Stitched Reads']
  24. colors = ['#ff9999', '#66b3ff', '#99ff99', '#ffcc99', '#c2c2f0']
  25. explode = (0.05, 0.05, 0.05, 0.05, 0.05)  # To explode a slice
  26.  
  27. # Create a pie chart with improved aesthetics
  28. plt.figure(figsize=(8, 8))
  29. plt.pie(data, labels=labels, autopct='%1.1f%%', startangle=140, colors=colors, pctdistance=0.85, explode=explode)
  30.  
  31. # Draw a circle in the center to make it a donut chart (optional)
  32. center_circle = plt.Circle((0, 0), 0.70, fc='white')
  33. fig = plt.gcf()
  34. fig.gca().add_artist(center_circle)
  35.  
  36. # Customize the plot
  37. plt.title('Distribution of Reads', fontsize=16, fontweight='bold')
  38. plt.axis('equal')  # Equal aspect ratio ensures that the pie chart is circular
  39. plt.legend(labels, loc='upper right', bbox_to_anchor=(0.85, 1))
  40.  
  41. # Move the legend to the left-hand side
  42. plt.legend(labels, loc='upper left', bbox_to_anchor=(-0.25, 0.9))
  43.  
  44. # Show the plot
  45. plt.tight_layout()
  46. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement