def main(): rw = RandomWalk() rw.fill_walk() fig, ax = plt.subplots() ax.plot(rw.x_values, rw.y_values, linewidth=5) ax.get_xaxis().set_visible(False) ax.get_yaxis().set_visible(False) plt.show()
def main(): """Root function.""" while True: rw = RandomWalk() rw.fill_walk() fig, ax = plt.subplots() point_numbers = range(rw.num_points) ax.scatter(rw.x_values, rw.y_values, s=5, c=point_numbers, cmap=plt.cm.Blues, edgecolors='none') ax.scatter(0, 0, c='green', s=50) ax.scatter(rw.x_values[-1], rw.y_values[-1], c='red', s=50) plt.show() keep_running = input('Do you want to make another walk? (y/n): ') if keep_running.lower() == 'n': break
import matplotlib.pyplot as plt from randomwalk import RandomWalk #Make a random walk , and plot the points while True: #Creacion de objeto y llamada al metodo rw = RandomWalk(50000) rw.fill_walk() #Generate scatter point_numbers = list(range(rw.num_points)) plt.scatter(rw.x_values,rw.y_values,c=point_numbers, cmap=plt.cm.Blues,edgecolor='none',s=1) #Emphasize the first and last points. plt.scatter(0,0,c='green',edgecolor='none',s=100) plt.scatter(rw.x_values[-1],rw.y_values[-1],c='red',edgecolor='none',s=100) plt.show() keep_running = input("Make another walk? (y/n): ") if keep_running == 'n': break
hist.y_title = 'Frequency of Result' hist.add('D6 + D6 + D6', result_frequency) hist.render_to_file('visual_3.svg') # Matplotlib to create a die-rolling visualisation plt.figure(figsize=(10, 6)) plt.scatter([x for x in range(2, max(results) + 1)], result_frequency, s=15) plt.xlabel('D6 + D6', fontsize=14) plt.ylabel('Frequency', fontsize=14) plt.show() # Pygal to create a visualisation for random walk (count how many times in the same coordinate) journey = RandomWalk(numpoints=50) journey.fill_walk() sorted_journey_set = sorted(set(journey.x_values)) same_coordinates_count = [] for x in sorted_journey_set: same_coordinates_count.append(journey.x_values.count(x)) hist = pygal.Bar() hist.x_title = 'x coordinate' hist.y_title = 'count' hist.x_labels = [str(x) for x in sorted_journey_set] hist.add('', same_coordinates_count) hist.render_to_file('randomwalk.svg')
import matplotlib.pyplot as plt from randomwalk import RandomWalk while True: rw_visual = RandomWalk() rw_visual.fill_walk() point_numbers = list(range(rw_visual.numpoints)) # c=point_numbers: gradient from first position to ending position plt.figure(figsize=(10, 6)) plt.scatter(rw_visual.x_values, rw_visual.y_values, c=point_numbers, cmap=plt.cm.Blues, edgecolor='none', s=10) plt.scatter(rw_visual.x_values[0], rw_visual.y_values[0], c='green', s=10) plt.scatter(rw_visual.x_values[-1], rw_visual.y_values[-1], c='red', s=10) plt.axes().get_xaxis().set_visible(False) plt.axes().get_yaxis().set_visible(False) plt.show() user_input = input('Do you want to make another plot? y/n ') if user_input.lower() == 'n': break
import matplotlib.pyplot as plt from randomwalk import RandomWalk molecular_path = RandomWalk() molecular_path.fill_walk() plt.figure(figsize=(10, 6)) plt.plot(molecular_path.x_values, molecular_path.y_values, linewidth=1) plt.scatter(molecular_path.x_values[0], molecular_path.y_values[0], c='green', s=15) plt.scatter(molecular_path.x_values[-1], molecular_path.y_values[-1], c='red', s=15) plt.show()