```
import numpy as np
import scipy as sp
import sympy

# Pylab combines the pyplot functionality (for plotting) with the numpy
# functionality (for mathematics and for working with arrays) in a single namespace
# aims to provide a closer MATLAB feel (the easy way). Note that his approach
# should only be used when doing some interactive quick and dirty data inspection.
# DO NOT USE THIS FOR SCRIPTS
#from pylab import *

# the convienient Matplotib plotting interface pyplot (the tidy/right way)
# use this for building scripts. The examples here will all use pyplot.
import matplotlib.pyplot as plt

# for using the matplotlib API directly (the hard and verbose way)
# use this when building applications, and/or backends
import matplotlib as mpl
```


```
# activate pop up plots
#%matplotlib qt
# or change to inline plots
%matplotlib inline
```


```
# some sample data
x = np.arange(-10,10,0.1)
```


```
page_width_cm = 13
dpi = 200
inch = 2.54 # inch in cm
# setting global plot configuration using the RC configuration style
plt.rc('font', family='serif')
plt.rc('xtick', labelsize=12) # tick labels
plt.rc('ytick', labelsize=20) # tick labels
plt.rc('axes', labelsize=20)  # axes labels
# If you don’t need LaTeX, don’t use it. It is slower to plot, and text
# looks just fine without. If you need it, e.g. for symbols, then use it.
#plt.rc('text', usetex=True) #<- P-E: Doesn't work on my Mac
```


```
# create a figure instance, note that figure size is given in inches!
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(8,6))
# set the big title (note aligment relative to figure)
fig.suptitle("suptitle 16, figure alignment", fontsize=16)

# actual plotting
ax.plot(x, x**2, label="label 12")


# set axes title (note aligment relative to axes)
ax.set_title("title 14, axes alignment", fontsize=14)

# axes labels
ax.set_xlabel('xlabel 12')
ax.set_ylabel(r'$y_{\alpha}$ 12', fontsize=8)

# legend
ax.legend(fontsize=12, loc="best")

# saving the figure in different formats
fig.savefig('figure-%03i.png' % dpi, dpi=dpi)
fig.savefig('figure.svg')
fig.savefig('figure.eps')
```


```
# following steps are only relevant when using figures as pop up windows (with %matplotlib qt)
# to update a figure with has been modified
fig.canvas.draw()
# show a figure
fig.show()
```


```
plt.plot(x,x**2)
#Write code to show grid in plot here
plt.grid()
```


```
plt.plot(x,x**2, label="label 12")
plt.legend(fontsize=12, loc="upper center")
```


```
stride = max( int(len(x) / 10), 1)
plt.plot(x,x**2, 'o-', markevery=stride)
```


```
fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(16,6))
ax[0].plot(x,x**2)
ax[1].plot(x,x**2)
```


```
X, Y = np.meshgrid(x,x)
```


```
Z=X**2+Y**2
CS = plt.contour(X, Y, Z)
```


```

```


```
fig, ax1 = plt.subplots()
ax1.plot(x,x**2)
ax2 = ax1.twinx()
ax2.plot(x,x**4, 'r')
plt.show()
```


```
plt.plot(x,x**2)
plt.axvline(5)
plt.axhline(50)
```


```
import datetime
dates = np.array([datetime.datetime.now() + datetime.timedelta(days=i) for i in xrange(24)])
fig, ax = plt.subplots(nrows=1, ncols=1)

ax.plot(dates,range(0,24))
fig.autofmt_xdate()
```


```
x=np.linspace(0,5*np.pi,1000)
y=np.sin(x)
yrand=y+np.random.normal(0,0.3,1000)
fig, ax = plt.subplots(nrows=1, ncols=1)
ax.plot(x,y,linewidth=4.0,linestyle='dashed',color='black',label="y = sin(x)")
ax.plot(x,yrand,'b.',markersize=5)
plt.ylim([-1.5,1.5])

n=10
cmap = mpl.cm.Accent
for i in range(1,n+1):
    coef = np.polyfit(x, y, i)
    polynomial = np.poly1d(coef)
    yFit = polynomial(x)
    labelFit="deg "+str(i-1)
    ax.plot(x,yFit,linewidth=2.0,color=cmap(i / float(n)),label=labelFit)
    
plt.legend(fontsize=12,  bbox_to_anchor=(1.02, 1), loc=2) 
```


```

```

8868ef491daec2ad097ae51a415c544e41fe3bab
ipynb
Jupyter Notebook
lesson 3/results/plaaExMatplotlib.ipynb
gtpedrosa/Python4WindEnergy
f8ad09018420cfb3a419173f97b129de7118d814
Apache-2.0
2015-01-19T18:21:10.000Z
2021-11-27T22:41:06.000Z
lesson 3/results/plaaExMatplotlib.ipynb
arash7444/Python4WindEnergy
8f97a5f86e81ce01d80dafb6f8104165fd3ad397
Apache-2.0
2016-05-24T06:07:07.000Z
2016-05-24T08:26:29.000Z
lesson 3/results/plaaExMatplotlib.ipynb
arash7444/Python4WindEnergy
8f97a5f86e81ce01d80dafb6f8104165fd3ad397
Apache-2.0
2015-06-26T14:44:07.000Z
2021-06-07T18:36:52.000Z
Qwen/Qwen-72B
1. YES
2. YES