Issue
I would like to plot sum of two sinusoidal in Python, like on attached screenshot. Could you please recommend how can i do it in matplotlib?
Solution
You already got two solutions. This one gives you something very similar to what you want. I could have made it look exactly like your output but I leave the remaining part of it as your exercise. Feel free to ask me if you have any doubts. This solution is based on https://matplotlib.org/examples/pylab_examples/finance_work2.html
import numpy as np
import matplotlib.pyplot as plt
left, width = 0.1, 0.8
rect1 = [left, 0.65, width, 0.25] # left, bottom, width, height
rect2 = [left, 0.4, width, 0.25]
rect3 = [left, 0.1, width, 0.3]
fig = plt.figure(figsize=(10, 6))
ax1 = fig.add_axes(rect1)
ax2 = fig.add_axes(rect2, sharex=ax1)
ax3 = fig.add_axes(rect3, sharex=ax1)
x = np.linspace(0, 6.5*np.pi, 200)
y1 = np.sin(x)
y2 = np.sin(2*x)
ax1.plot(x, y1, color='b', lw=2)
ax2.plot(x, y2, color='g', lw=2)
ax3.plot(x, y1+y2, color='r', lw=2)
ax3.get_xaxis().set_ticks([])
for ax in [ax1, ax2, ax3]:
ax.hlines(0, 0, 6.5*np.pi, color='black')
for key in ['right', 'top', 'bottom']:
ax.spines[key].set_visible(False)
plt.xlim(0, 6.6*np.pi)
ax3.text(2, 0.9, 'Sum signal', fontsize=14)
Output
Answered By - Sheldore
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.