# Python matplotlib 説明図を書いてみる >1個だけ表示してみる

damyarou様
ありがとうございます。
(参考)Python matplotlib 説明図を書いてみる
https://qiita.com/damyarou/items/eafcf27aa1a7852d32e9

# 環境

• windows7
• PyCharm 2017.3.2

# 1個だけ表示してみる

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as tick

fsz=20   # font size
xmin=-2
xmax=11
dx=1
ymin=-5
ymax=7
dy=1

fig=plt.figure(figsize=(8,8),facecolor='w')
plt.rcParams['font.size']=fsz
plt.rcParams['font.family']='sans-serif'

iflag=0
plt.xlim([xmin,xmax])
plt.ylim([ymin,ymax])
if iflag==0:
plt.axis('off')
else:
plt.xlabel('x_axis')
plt.ylabel('y_axis')
plt.xticks(np.arange(xmin,xmax+dx,dx))
plt.yticks(np.arange(ymin,ymax+dy,dy))
plt.grid(color='#999999',linestyle='solid')

# draw plate including boundary condition (hatch)
lx=5; ly=4; dd=0.5
#水平線
plt.plot([0,lx],[ly/2,ly/2],color='#000000',lw=1)

# draw deflection curve
p=1; E=1; I=1
xx=np.linspace(0,lx,21)
y=p*lx**4/24/E/I*((xx/lx)**2-2*(xx/lx)**3+(xx/lx)**4)
y=-y/np.max(y)*0.5+ly/2
plt.plot(xx,y,color='#000000',lw=1)

yy=np.linspace(0,ly,21)
x=p*ly**4/24/E/I*((yy/ly)**2-2*(yy/ly)**3+(yy/ly)**4)
x=x/np.max(x)*0.5+lx/2
plt.text(4,1.4,r'$\delta_x$',va='center',ha='center',fontsize=fsz,rotation=0)

# draw moment diagram
y0=-3; x0=8.5
mx=p*lx**2/2*(-1/6+xx/lx-xx**2/lx**2)
my=p*ly**2/2*(-1/6+yy/ly-yy**2/ly**2)
mx=mx/np.min(mx)*1.0+y0
my=-my/np.min(my)*1.0+x0
plt.plot(xx,mx,color='#000000',lw=1)
plt.fill_between(xx,mx,y0,color='#aaaaaa')
plt.plot([0,0,lx,lx],[y0+1,y0,y0,y0+1],color='#000000',lw=1)

# draw text information
ss=r'$-\frac{w_x\cdot l_x{}^2}{12}$'; xs=lx; ys=y0+1.1;rt=0
plt.text(xs,ys,ss,ha='left',va='center',rotation=rt)
ss=r'$\frac{w_x\cdot l_x{}^2}{24}$'; xs=lx/2; ys=y0-1.0;rt=0
plt.text(xs,ys,ss,ha='center',va='center',rotation=rt)

ss='Fixed'
xs=0+0.05; ys=ly/4*3; rt=90; plt.text(xs,ys,ss,ha='left',va='center',rotation=rt,fontsize=fsz-2)
xs=lx-0.05; ys=ly/4*3; rt=90; plt.text(xs,ys,ss,ha='right',va='center',rotation=rt,fontsize=fsz-2)

col='#000000'
xx1=np.arange(0,5+0.5,0.5)
wx=0.5
for x1 in xx1:
x2=x1;y1=y0+1.5; y2=y1+wx; sv=0
plt.annotate('',
xy=(x1,y1), xycoords='data',
xytext=(x2,y2), textcoords='data', fontsize=0,
connectionstyle='arc3',facecolor=col,edgecolor=col))

plt.tight_layout()
plt.show()


# 以下は,私の設定不足のため、実行途中に発生したエラーです。

(参考)PyCharmでNumPyを使うためのメモ書き
https://qiita.com/mao_ya/items/82f278723734779376a4

C:\Users\xxxx\PycharmProjects\untitled3\venv\Scripts\python.exe C:/Users/xxxx/PycharmProjects/untitled3/tawamisen.py
Traceback (most recent call last):
File "C:/Users/xxxx/PycharmProjects/untitled3/tawamisen.py", line 3, in <module>
xx=np.linspace(0,lx,21)
NameError: name 'np' is not defined
Process finished with exit code 1

C:\Users\xxxx\PycharmProjects\untitled3\venv\Scripts\python.exe C:/Users/xxxx/PycharmProjects/untitled3/tawamisen.py
Traceback (most recent call last):
File "C:/Users/xxxx/PycharmProjects/untitled3/tawamisen.py", line 1, in <module>
import numpy as np
ModuleNotFoundError: No module named 'numpy'
Process finished with exit code 1

C:\Users\xxxx\PycharmProjects\untitled3\venv\Scripts\python.exe C:/Users/xxxx/PycharmProjects/untitled3/tawamisen.py
Traceback (most recent call last):
File "C:/Users/xxxx/PycharmProjects/untitled3/tawamisen.py", line 2, in <module>
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
Process finished with exit code 1

C:\Users\xxxx\PycharmProjects\untitled3\venv\Scripts\python.exe C:/Users/xxxx/PycharmProjects/untitled3/tawamisen.py
Traceback (most recent call last):
File "C:/Users/xxxx/PycharmProjects/untitled3/tawamisen.py", line 15, in <module>
xx=np.linspace(0,lx,21)
NameError: name 'lx' is not defined
Process finished with exit code 1

C:\Users\xxxx\PycharmProjects\untitled3\venv\Scripts\python.exe C:/Users/xxxx/PycharmProjects/untitled3/tawamisen.py
Traceback (most recent call last):
File "C:/Users/cxxxx/PycharmProjects/untitled3/tawamisen.py", line 33, in <module>
mx=p*lx**2/2*(-1/6+xx/lx-xx**2/lx**2)
NameError: name 'p' is not defined
Process finished with exit code 1