python - Why is my line clipping in matplotlib? -
i trying draw series of lines. lines same length, , randomly switch colors random length (blue orange). drawing lines in blue , overlaying orange on top. can see picture there clipped parts of lines grey. cannot figure out why happening. related believe labels not moving left alignment should. appreciated.
import numpy np import matplotlib.pyplot plt import matplotlib.lines mlines import random plt.close('all') fig, ax = plt.subplots(figsize=(15,11)) def label(xy, text): y = xy[1] - 2 ax.text(xy[0], y, text, ha="left", family='sans-serif', size=14) def draw_chromosome(start, stop, y, color): x = np.array([start, stop]) y = np.array([y, y]) line = mlines.line2d(x , y, lw=10., color=color) ax.add_line(line) x = 50 y = 100 chr = 1 in range(22): draw_chromosome(x, 120, y, "#1c2f4d") j = 0 while j < 120: print j length = 1 if random.randint(1, 100) > 90: length = random.randint(1, 120-j) draw_chromosome(j, j+length, y, "#fa9b00") j = j+length+1 label([x, y], "chromosome%i" % chr) y -= 3 chr += 1 plt.axis('equal') plt.axis('off') plt.tight_layout() plt.show()
you're drawing blue background x = 50 x = 120.
replace line:
draw_chromosome(x, 120, y, "#1c2f4d")
with this:
draw_chromosome(0, 120, y, "#1c2f4d")
to draw blue line way across.
alternately, if want move labels left, can set x=0
instead of setting 50.
Comments
Post a Comment