-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplots.py
38 lines (30 loc) · 941 Bytes
/
plots.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
from Bio import SeqIO
#--------1. Line plot--------
x = np.arange(1, 23, 2)
y = np.arange(20, 42, 2)
plt.xticks(x)
plt.yticks(y)
plt.xlim(1, 21)
plt.ylim(20,40)
plt.plot(x, y)
plt.xlabel('Odd numbers')
plt.ylabel('Even numbers')
plt.title('1. Line plot')
plt.savefig('lineplot.png')
#--------2. Sequence length distribution--------
def seq_length_distribution(path):
sizes = [len(rec) for rec in SeqIO.parse(path, 'fasta')]
plt.hist(sizes, edgecolor='black')
plt.title("%i sequences\nLengths %i to %i" % (len(sizes), min(sizes), max(sizes)))
plt.xlabel('Sequence length (bp)')
plt.ylabel('Count')
plt.savefig(path + '.png')
seq_length_distribution('example.fasta')
#--------3. My favourite plot--------
plot_data = np.random.rand(10, 12)
ax = sns.heatmap(plot_data)
plt.title('My favourite plot is heatmap!')
plt.savefig('heatmap.png')