Matplotlib > 散布図の描画 + 補間された曲線 > v0.1: scipy.interpolate.spline補間値が0.0になる > v0.2: バグ修正 > v0.3: 曲線をやめて直線でつなぐ

```txt:動作環境
GeForce GTX 1070 (8GB)
ASRock Z170M Pro4S [Intel Z170chipset]
Ubuntu 16.04 LTS desktop amd64
TensorFlow v1.2.1
cuDNN v5.1 for Linux
CUDA v8.0
Python 3.5.2
IPython 6.0.0 -- An enhanced Interactive Python.
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
scipy v0.19.1
geopandas v0.3.0
MATLAB R2017b (Home Edition)
ADDA v.1.3b6
```

### 処理概要

- 散布図を描画する
- 点の間を補間処理した曲線を加える

### 参考

https://stackoverflow.com/questions/5283649/plot-smooth-line-with-pyplot
> answered Mar 12 '11 at 17:09
Olivier Verdier

https://docs.scipy.org/doc/scipy-0.18.1/reference/generated/scipy.interpolate.spline.html

### データ

```res.qext_171217.txt
#Nori,Qext(avg)
30,3.4076437
100,3.4124564
300,3.4128675
500,3.4130134
1000,3.4130940
2000,3.4131344
```

### code v0.1

Jupyterコード。

```py:lineplot_Qext_171223.ipynb
%matplotlib inline

import numpy as np
import matplotlib.pyplot as plt
from pylab import rcParams
from scipy.interpolate import spline

'''
v0.1 Dec. 23, 2017
  - add lineplot
  - plot Qext as a scatterplot
'''

#rcParams['figure.figsize'] = 10,10
rcParams['figure.dpi'] = 130

data1 = np.genfromtxt('res.qext_171217.txt', delimiter=',')
inp1 = data1[:,0]
out1 = data1[:,1]

fig = plt.figure()

ax1 = fig.add_subplot(1,1,1)

# 1. scatterplot
ax1.scatter(inp1, out1, label='chebyshev 0.7 12 -size 10', color='blue', marker='o')

# 2. lineplot
inp2 = np.linspace(inp1[0], inp1[-1], 100)
out2 = spline(inp1, out1, inp2)
print(inp1[:10])
print(out1[:10])
print(inp2[:5], inp2[-5:])
print(out2[:10])
ax1.plot(inp2, out2, color='blue', linestyle='solid')

#ax1.plot(inp1, out1, color='blue',  linestyle='solid')

ax1.set_xscale("log")
ax1.set_xlabel('# orientation')
ax1.set_ylabel('Qext')
ax1.grid(True)
ax1.legend()
ax1.set_xlim([1.0,10000.0])

#fig.show()
```

```txt:run
[   30.   100.   300.   500.  1000.  2000.]
[ 3.4076437  3.4124564  3.4128675  3.4130134  3.413094   3.4131344]
[  30.          49.8989899   69.7979798   89.6969697  109.5959596] [ 1920.4040404  1940.3030303  1960.2020202  1980.1010101  2000.       ]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
```

![qiita.png](https://qiita-image-store.s3.amazonaws.com/0/32870/0b09ca0d-8f19-3497-e030-ab3fd198f4da.png)

補間が失敗して、値が0.0になっている。

### code v0.2

inp1とout1をnp.arrayにしてみた。

```py
inp1 = np.array(inp1)
out1 = np.array(out1)
```

```py:lineplot_Qext_171223.ipynb
%matplotlib inline

import numpy as np
import matplotlib.pyplot as plt
from pylab import rcParams
from scipy.interpolate import spline

'''
v0.2 Dec. 23, 2017
  - fix bug: interpolated [out2] was 0.0
v0.1 Dec. 23, 2017
  - add lineplot
  - plot Qext as a scatterplot
'''

#rcParams['figure.figsize'] = 10,10
rcParams['figure.dpi'] = 130

data1 = np.genfromtxt('res.qext_171217.txt', delimiter=',')
inp1 = data1[:,0]
out1 = data1[:,1]
inp1 = np.array(inp1)
out1 = np.array(out1)

fig = plt.figure()

ax1 = fig.add_subplot(1,1,1)

# 1. scatterplot
ax1.scatter(inp1, out1, label='chebyshev 0.7 12 -size 10', color='blue', marker='o')

# 2. lineplot
inp2 = np.linspace(inp1[0], inp1[-1], 100)
out2 = spline(inp1, out1, inp2)
print(inp1[:10])
print(out1[:10])
print(inp2[:5], inp2[-5:])
print(out2[:10])
ax1.plot(inp2, out2, color='blue', linestyle='solid')

#ax1.plot(inp1, out1, color='blue',  linestyle='solid')

ax1.set_xscale("log")
ax1.set_xlabel('# orientation')
ax1.set_ylabel('Qext')
ax1.grid(True)
ax1.legend()
ax1.set_xlim([1.0,10000.0])

#fig.show()
```

![qiita.png](https://qiita-image-store.s3.amazonaws.com/0/32870/256aebf8-8373-2c59-7417-ede46ca60e6f.png)

補間できたが、コレジャナイロボ発進。


### code v0.3

```py:lineplot_Qext_171223.ipynb
%matplotlib inline

import numpy as np
import matplotlib.pyplot as plt
from pylab import rcParams
from scipy.interpolate import spline

'''
v0.3 Dec. 23, 2017
  - use original data for the .plot instead of interpolated one
v0.2 Dec. 23, 2017
  - fix bug: interpolated [out2] was 0.0
v0.1 Dec. 23, 2017
  - add lineplot
  - plot Qext as a scatterplot
'''

#rcParams['figure.figsize'] = 10,10
rcParams['figure.dpi'] = 130

data1 = np.genfromtxt('res.qext_171217.txt', delimiter=',')
inp1 = data1[:,0]
out1 = data1[:,1]
inp1 = np.array(inp1)
out1 = np.array(out1)

fig = plt.figure()

ax1 = fig.add_subplot(1,1,1)

# 1. scatterplot
ax1.scatter(inp1, out1, label='chebyshev 0.7 12 -size 10', color='blue', marker='o')

# 2. lineplot
ax1.plot(inp1, out1, color='blue',  linestyle='solid')

ax1.set_xscale("log")
ax1.set_xlabel('# orientation')
ax1.set_ylabel('Qext')
ax1.grid(True)
ax1.legend()
ax1.set_xlim([1.0,10000.0])

#fig.show()
```

![qiita.png](https://qiita-image-store.s3.amazonaws.com/0/32870/34930246-20f8-ff4c-9e38-276fec9f92b2.png)

複数の結果を比較する場合はこちらがいいかもしれない。

![qiita.png](https://qiita-image-store.s3.amazonaws.com/0/32870/3f8dbfb7-f131-6f78-79e2-fc0e86cccbef.png)




### 関連

- [link > Python で 1 変量データ補間 > SciPy > interpolate.*](https://qiita.com/7of9/items/dbd21f4190fc3c0ee3e6)
- [matplotlib / Jupyter > 散布図を重ねる / color設定 / marker設定](https://qiita.com/7of9/items/eb1f837b1d9f6314a7bc)
- [Jupyter | Matplotlib > 凹凸の激しい形状の可視化 > v0.4, v0.5: ADDA InitField-Yファイル読込み > Sphere | Prism (N=3) | Chevyshev particles](https://qiita.com/7of9/items/32480e2431af914c335b)