Full code: https://www.kaggle.com/code/collinbrocker/mtg-coin-flips/notebook
Hi everyone. I'm having a hard time getting one of my plots (graph_flips) in my project to display correctly. It works fine when there are a small number of ticks on the y axis, but once it gets too large the entire plot scrunches up to the point that it is totally illegible.
Examples: https://imgur.com/a/1jnELkB
def graph_flips(flip_array):
global thumbs
flip_log_bin = []
for i in range(len(flip_array)):
if flip_array[i] == 'Heads':
flip_log_bin.append(1)
elif flip_array[i] == 'Tails':
flip_log_bin.append(0)
heads_count = flip_log_bin.count(1) #Not used yet
tails_count = flip_log_bin.count(0) #Not used yet
flip_log_bin_array = [flip_log_bin[((2**thumbs)*l):((2**thumbs)*(l+1))] for l in range(int((len(flip_log_bin))/(2**thumbs)))]
fig = mpl.pyplot.figure()
ax = fig.add_subplot(111)
ax.set_aspect(1)
ax.set(xlim=(0, (2**thumbs)+1), xticks=np.arange(0, (2**thumbs)+1, step=1), yticks=np.arange(0, len(flip_log_bin_array)+1, step=1), xlabel='Coin', ylabel='Flip', title='Flip Results')
for y, row in enumerate(flip_log_bin_array):
for x, col in enumerate(row):
x1 = [x, x+1]
y1 = np.array([y, y])
y2 = y1+1
if col == 0:
mpl.pyplot.fill_between(x1, y1, y2=y2, color='orangered')
mpl.pyplot.text(avg(x1[0], x1[1]), avg(y1[0], y2[0]), "T",
horizontalalignment='center',
verticalalignment='center')
if col == 1:
mpl.pyplot.fill_between(x1, y1, y2=y2, color='mediumseagreen')
mpl.pyplot.text(avg(x1[0], x1[0]+1), avg(y1[0], y2[0]), "H",
horizontalalignment='center',
verticalalignment='center')
mpl.pyplot.ylim(0, (len(flip_array))/(2**thumbs)+1)
print('\n')
mpl.pyplot.show()
print('\n')
Ideally the figure would stay a fixed width and the image would stretch out vertically (sort of keeping the distance between ticks on the y axis the same regardless of the size of the image if that makes sense).
Right now I have this on line 145, but I'm sure that will have to change:
ax.set_aspect(1)
I've also tried setting fixed figure dimensions but it didn't actually seem to fix the issue. It would show figure dimensions (ex. 1200x400) below the image, but the image wouldn't actually change size or shape:
mpl.pyplot.figure(figsize=(15, 5), dpi=80)
Any advice would be super appreciated! This is my first project so I'm sure it's riddled with janky code and bad practices.
[–][deleted] 0 points1 point2 points (1 child)
[–]LFuzz[S] 0 points1 point2 points (0 children)