def make_movie(input_filename, output_filename): cluster, gas = read_set_from_file(input_filename, 'amuse', names=("cluster", "gas")) lim = abs(next(cluster.history).position).max() fig = pyplot.figure(figsize=[10,10]) artists = [] for cl, gas in zip(cluster.history, gas.history): print "Creating frame at time", cl.get_timestamp() points = aplot.scatter(cl.x, cl.y, c='black') gas_points = aplot.scatter(gas.x, gas.y, s=100, c='b', edgecolors='none', alpha=0.3, rasterized=True) time_label = "t = {:.2f} Myr".format( cl.get_timestamp().value_in(units.Myr)) text = aplot.text(-4./5.*lim, 4./5.*lim, time_label) aplot.xlabel("X") aplot.ylabel("Y") pyplot.axis('equal') aplot.xlim(-lim, lim) aplot.ylim(-lim, lim) pyplot.savefig("plots/test."+str(cl.get_timestamp().value_in(units.Myr))+".png") pyplot.close() artists.append((points, gas_points, text))
def test4(self): """ Test text in a plot """ if not HAS_MATPLOTLIB: return self.skip() pyplot.clf() set_printing_strategy('default') x = numpy.linspace(0, 100, 100) | units.yr y = numpy.linspace(0, 200, 100) | units.RSun aplot.plot(x, y) text = aplot.text(50 | units.yr, 0.5 | units.AU, "test text") self.assertEquals(50., text.get_position()[0]) self.assertAlmostEquals(107.546995464, text.get_position()[1])
def test4(self): """ Test text in a plot """ if not HAS_MATPLOTLIB: return self.skip() pyplot.clf() set_printing_strategy('default') x = numpy.linspace(0, 100, 100) | units.yr y = numpy.linspace(0, 200, 100) | units.RSun aplot.plot(x, y) text = aplot.text(50|units.yr, 0.5|units.AU, "test text") self.assertEquals(50., text.get_position()[0]) self.assertAlmostEquals(107.546995464, text.get_position()[1])
fig = pyplot.figure(figsize=[10, 10]) artists = [] cl = None gas = None for c, g in zip(cluster.history, gascloud.history): cl = c gas = g points = aplot.scatter(cl.x, cl.y, c='black', label='Stellar Cluster') gas_points = aplot.scatter(gas.x, gas.y, s=100, c='b', edgecolors='none', alpha=0.3, rasterized=True, label='Giant Molecular Cloud') time_label = r'$t_{\rm end}$ ' + "= {:.2f} Myr".format(cl.get_timestamp(). value_in(units.Myr)) text = aplot.text(-4./5.*lim, 4./5.*lim, time_label) aplot.xlabel("X") aplot.ylabel("Y") pyplot.axis('equal') aplot.xlim(-lim, lim) aplot.ylim(-lim, lim) pyplot.legend() pyplot.title(r'Cluster orbitting GMC with $d$={0}, $v_\infty$={1}' .format(impact_parameter, v_infinity) + r', at $t_{\rm end}$') pyplot.savefig(out_file) pyplot.close()