Skip to content

Commit 684beb7

Browse files
authored
Sine cosine plot extension
1 parent ee67b81 commit 684beb7

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

senocoseno_plot4.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Moving the axes and adding a caption to the cosine sine grap
2+
3+
import pylab as pl
4+
import numpy as np
5+
6+
# Creates a figure of size 10x6 points, 80 points per inch
7+
# Changing figure to make it more horizontal
8+
pl.figure(figsize=(10, 6), dpi=80)
9+
10+
# Creates a new subplot from a 1x1 grid
11+
pl.subplot(1, 1, 1)
12+
13+
X = np.linspace(-np.pi, np.pi, 256, endpoint=True)
14+
C, S = np.cos(X), np.sin(X)
15+
16+
# Cosine in blue, sine in red both with thicker lines and definition of names for each line in the graph
17+
pl.plot(X, C, color="blue", linewidth=2.5, linestyle="-", label="cosine")
18+
pl.plot(X, S, color="red", linewidth=2.5, linestyle="-", label="sine")
19+
20+
# Subtitle
21+
pl.legend(loc='upper left')
22+
23+
# Sets the limits on x
24+
pl.xlim(-4.0, 4.0)
25+
26+
# # moving the secondary axes
27+
ax = pl.gca()
28+
ax.spines['right'].set_color('none')
29+
ax.spines['top'].set_color('none')
30+
ax.xaxis.set_ticks_position('bottom')
31+
ax.spines['bottom'].set_position(('data',0))
32+
ax.yaxis.set_ticks_position('left')
33+
ax.spines['left'].set_position(('data',0))
34+
35+
# Sets the x marks
36+
pl.xticks([-np.pi, -np.pi/2, 0, np.pi/2, np.pi],
37+
[r'$-\pi$', r'$-\pi/2$', r'$0$', r'$+\pi/2$', r'$+\pi$'])
38+
# Marker x showing only explicit essential values
39+
40+
# Defines the limits in y
41+
#pl.ylim(-1.0, 1.0)
42+
43+
# Sets the y-marks
44+
pl.yticks([-1, 0, +1],
45+
[r'$-1$', r'$0$', r'$+1$'])
46+
# Marker y showing only explicit essential values
47+
48+
# Saves the figure using 72 dots per inch
49+
#pl.savefig("sencos.png", dpi=72)
50+
51+
# Shows the result on the screen
52+
pl.show()

0 commit comments

Comments
 (0)