The x-axis limits might be set like the following so 5000 years ago is on the left of the plot and the present is on the right. For example, suppose x represents the number of years before present. fig, (ax1, ax2) = plt.subplots(2, figsize=(9,6))Īx1.plot(xs, rawsignal) # plot rawsignal in the first AxesĪx1.set(title='Signal') # set the title of the first AxesĪx2.plot(abs(fft)) # plot FFT in the second AxesĪx2.set(ylim=(0, 100), title='FFT') # set title and y-limit of the second Axesīoth sets of codes produce the same following output. Limits may be passed in reverse order to flip the direction of the x-axis. Axes instances define set() method which can be used to set a whole host of properties including y-limit/title etc. np.cos (T), np.sin (T), c 'k', lw 3.) plt.axes ().setaspect ('equal') plt. Then again, using the object-oriented interface is less verbose and clearer. To accomplish this, we will need to play with the pyplot API and the Axes object, as shown in the following code: import numpy as np import matplotlib.pyplot as plt T np.linspace (0, 2 np.pi, 1024) plt.plot (2. Change the axis limits with ax.setylim() and ax. Plt.subplot(2, 1, 2, title='FFT', ylim=(0,100)) # second subplot 1.1 Formatting Options Set the title with ax.settitle() Set the axis labels with ax.setylabel() and ax. Plt.subplot(2, 1, 1, title='Signal') # first subplot Plt.figure(figsize=(9,6)) # create figure import matplotlib.pyplot as plt import numpy as np an np.linspace(0, 2 np.pi, 100) fig, axs plt.subplots(2, 2) axs0, 0.plot(3 np.cos(an), 3 np.sin(an)) axs0, 0. It's also possible to set ylim/ xlim at the time of adding a subplot to the existing figure instance ( plt.subplot admits ylim= argument).
0 Comments
Leave a Reply. |