CoCalc Public Filestmp / Test_graphics.sagewsOpen in with one click!
Authors: Harald Schilly, ℏal Snyder, William A. Stein
#Test_graphics.sagews var('z'); x = [1926, 1927, 1928, 1929, 1930, 1931, 1932, 1933] y = [ 4.61,5.24, 10.47, 20.24, 28.83, 43.40, 48.34, 50.80] from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure from matplotlib.ticker import * fig = Figure(figsize=[5,3]) canvas = FigureCanvas(fig) ax = fig.add_subplot(111) fig.tight_layout() ax.xaxis.set_major_formatter( FormatStrFormatter( '%d' )) ax.yaxis.set_major_locator( MaxNLocator(10) ) ax.yaxis.set_major_formatter( FormatStrFormatter( '%d' )) ax.yaxis.grid(True, linestyle='-', which='minor') ax.grid(True, linestyle='-', linewidth=.5) ax.set_title('Distance by transport airplanes in the US') ax.set_xlabel('Year') ax.set_ylabel('Distance(x1^6)miles') ax.semilogy(x,y, 'bo-', linewidth=1.0 ) #ax.plot(10*z,z,0,0.1,20, 'bo-', linewidth=1.0 ) #v=sin(x) #ax.plot(v) #ax.figsize=8 canvas.print_figure('ex2_logX.png') ax
z <matplotlib.text.Text object at 0x7f1126faa4d0> <matplotlib.text.Text object at 0x7f1124c7f690> <matplotlib.text.Text object at 0x7f1124caf7d0> [<matplotlib.lines.Line2D object at 0x7f1124aaa910>]
import matplotlib.pyplot as plt import numpy as np from matplotlib.ticker import MultipleLocator, FormatStrFormatter majorLocator = MultipleLocator(20) #20 used majorFormatter = FormatStrFormatter('%d') minorLocator = MultipleLocator(5) #5 not used #t = np.arange(0.0, 100.0, 2) #s = np.sin(0.1*np.pi*t)*np.exp(-t*0.01) t = np.arange(0.0, 100.0, 0.1) s1 =abs( sin(0.1*pi*t)*exp(-t*0.01) )+0.1 s2 =abs( sin(0.1*pi*t)*exp(-t*0.01) )+0.5 fig, ax = plt.subplots(figsize=[5,4]) #effect at this place******************* #ax = plt.subplots(figsize=[6,6]) #effect at this place******************* plt.semilogy(t,s1) plt.semilogy(t,s2) ax.xaxis.set_major_locator(majorLocator) ax.xaxis.set_major_formatter(majorFormatter) #for the minor ticks, use no labels; default NullFormatter #ax.xaxis.set_minor_locator(minorLocator) #ax.xaxis.grid(True, linestyle='-', which='minor') #ax.yaxis.grid(True, linestyle='-', which='minor') #ax.grid(True, linestyle='-', linewidth=.5) ax.grid(True, linewidth=.5) ax.set_title('Distance by transport airplanes in the US',fontsize=8) ax.set_xlabel('Year',fontsize=8) ax.set_ylabel('Distance(x1^6)miles',fontsize=8) plt.show()
[<matplotlib.lines.Line2D object at 0x7fde161313d0>] [<matplotlib.lines.Line2D object at 0x7fde180e6550>] <matplotlib.text.Text object at 0x7fde180b0b90> <matplotlib.text.Text object at 0x7fde162d8fd0> <matplotlib.text.Text object at 0x7fde148c1ed0>
import matplotlib.pyplot as plt import numpy as np xmin,xmax=-np.pi, np.pi x=np.arange(xmin,xmax,0.1) y_sin=np.sin(x) y_cos=np.cos(x) # sinのプロット plt.subplot(2, 1, 1) plt.plot(x, y_sin) plt.title(r"$\sin x$") plt.xlim(xmin, xmax) plt.ylim(-1.3, 1.3) # cosのプロット plt.subplot(2, 1, 2) plt.plot(x, y_cos) plt.title(r"$\cos x$") plt.xlim(xmin, xmax) plt.ylim(-1.3, 1.3) plt.tight_layout() # タイトルの被りを防ぐ
[<matplotlib.lines.Line2D object at 0x7fde164677d0>] <matplotlib.text.Text object at 0x7fde162b7b90> (-3.141592653589793, 3.141592653589793) (-1.30000000000000, 1.30000000000000)
[<matplotlib.lines.Line2D object at 0x7fde149889d0>] <matplotlib.text.Text object at 0x7fde14916710> (-3.141592653589793, 3.141592653589793) (-1.30000000000000, 1.30000000000000)
#Test_graphics.sagews var('z,x,y') #x = srange(500) y = srange(500) from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure from matplotlib.ticker import * fig = Figure(figsize=[5,6]) canvas = FigureCanvas(fig) #canvas.subplots(figsize=[5,3]) #effect at this place******************* ax = fig.add_subplot(211) fig.tight_layout() #ax.xaxis.set_major_formatter( FormatStrFormatter( '%d' )) #ax.yaxis.set_major_locator( MaxNLocator(10) ) #ax.yaxis.set_major_formatter( FormatStrFormatter( '%d' )) #ax.yaxis.grid(True, linestyle='-', which='minor') ax.grid(True, linestyle='-', linewidth=.5) ax.set_title('Distance by transport airplanes in the US', fontsize='8') ax.set_xlabel('Year', fontsize='8') ax.set_ylabel('Distance(x1^6)miles', fontsize='8') z=[sin(t/20)*100 for t in y] ax.plot(y,z, 'b-', linewidth=1.0 ) ax = fig.add_subplot(212) fig.tight_layout() z=[sin(t/20)*10 for t in y] ax.grid(True, linestyle='-', linewidth=.5) ax.set_title('Distance by transport airplanes in the US', fontsize='8') ax.set_xlabel('Year', fontsize='8') ax.set_ylabel('Distance(x1^6)miles', fontsize='8') ax.plot(y,z, 'b-', linewidth=1.0, color='red' ) #ax.plot(z,0,0.1,10,10*z, 'bo-', linewidth=1.0 ) #v=sin(x) #ax.plot(v) #ax.figsize=8 canvas.print_figure('ex2_logXX.png') #ax salvus.file('ex2_logXX.png') #fig.tight_layout() # タイトルの被りを防ぐ
(z, x, y) <matplotlib.text.Text object at 0x7f112497d490> <matplotlib.text.Text object at 0x7f112546df10> <matplotlib.text.Text object at 0x7f1126cfae50> [<matplotlib.lines.Line2D object at 0x7f112548f750>] <matplotlib.text.Text object at 0x7f11249a7710> <matplotlib.text.Text object at 0x7f1125447c50> <matplotlib.text.Text object at 0x7f11253f2f50> [<matplotlib.lines.Line2D object at 0x7f11249a4b10>]