Jupyter + Matplotlib > link: colorsをリストで渡してax.scatter()で描画する > showNoriMueller_180203.ipynb 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
```

### 関連

- [matplotlib / Jupyter > 散布図を重ねる / color設定 / marker設定](https://qiita.com/7of9/items/eb1f837b1d9f6314a7bc)

上記では、散布図で２種類のデータを描画している。

Hammersley NodesとIcosahedral Nodes (+Fibonacci Nodes[計算中])の結果を比較したい。

[matplotlib.pyplot.scatter](https://matplotlib.org/devdocs/api/_as_gen/matplotlib.pyplot.scatter.html)において、color(c)引数にリストを渡す方法はないだろうか。

### link

https://stackoverflow.com/questions/30511340/add-a-list-of-labels-in-pythons-matplotlib
上記ではリストをzipで展開し、`# Plot point by point`している。

### code v0.2, v0.3

[showNoriMueller_180203.ipynb v0.1](https://qiita.com/7of9/items/d3eb5a56ab46c970f34c)に上記の処理を実装した。

```py:showNoriMueller_180203.ipynb
%matplotlib inline
import matplotlib.pyplot as plt
from matplotlib import cm, colors
from mpl_toolkits.mplot3d import Axes3D
from pylab import rcParams
import numpy as np
import time


"""
v0.3 Feb. 17, 2018
  - IN_FILES[] has results for [Fibonacci nodes]
v0.2 Feb. 11, 2018
  - turn off [text labels]
  - show in different colors for different node sets
      + draw_asANumberOfOrientations() takes [colors] arg
      + add get_colorsOfNodes()
      + IN_FILES[] has results for [Icosahedral nodes]
      + add Nori_clrs[]
v0.1 Feb. 03, 2018
  - draw_asANumberOfOrientations() draws [Nori] text
  - add draw_asANumberOfOrientations()
  - add get_numberOfOrientations()
  - remove draw_degreeOfPolarization()
  - remove draw_phaseFunction()
  - branched from [showMueller_180113]
---
v0.6 Jan. 28, 2018
  - fix bug > read_s11_and_polarization() was reading [IN_FILE] not [infile]
v0.5 Jan. 20, 2018
  - read list of files defined at IN_FILES[]
  - add read_s11_and_polarization()
  - change from [scatter plot] to [line plot]
v0.4 Jan. 14, 2018
  - refactor > remove_outsideOf() > use Boolean indexing
  - refactor > use set_xticks() instead of plt.xticks()
v0.3 Jan. 13, 2018
  - show enlarged version (3rd and 4th graph)
    + add remove_outsideOf()
v0.2 Jan. 13, 2018
  - show [degree of polarization]
v0.1 Jan. 13, 2018
  - set x axis ticks to 30 degree
  - show [S11] as a function of [Theta]
"""

# Coding rule:PEP8

rcParams['figure.figsize'] = 10, 7
rcParams['figure.dpi'] = 110


def read_s11_and_polarization(infile):
    dat = np.genfromtxt(infile, delimiter=' ', skip_header=1)
    thetas = []
    s11s = []
    pols = []
    for elem in dat:
        thetas += [elem[0]]
        s11s += [elem[1]]
        pols += [-elem[2] / elem[1] * 100]
    return thetas, s11s, pols


def remove_outsideOf(xs, ys, xmin, xmax):
    xns, yns = np.array(xs), np.array(ys)
    keep_flgs = (xns >= xmin) & (xns <= xmax)
    return xns[keep_flgs], yns[keep_flgs]


IN_FILES = [
    # 1234567890123456
    # 1. Hammersley Nodes
    'mueller_gHN_N0030',
    'mueller_gHN_N0060',
    'mueller_gHN_N0100',
    'mueller_gHN_N0300',
    'mueller_gHN_N0500',
    'mueller_gHN_N1000',
    'mueller_gHN_N1500',
    'mueller_gHN_N2000',
    # 2. Icosahedral Nodes (type=0)
    'mueller_gIN_N0012',
    'mueller_gIN_N0042',
    'mueller_gIN_N0162',
    'mueller_gIN_N0642',
    'mueller_gIN_N2562',
    # 3. Fibonacci Nodes
    'mueller_gFN_N0031',
    'mueller_gFN_N0061',
    'mueller_gFN_N0101',
    'mueller_gFN_N0301',
    'mueller_gFN_N0501',
    'mueller_gFN_N1001',
    'mueller_gFN_N1501',
    'mueller_gFN_N2001',
]  # from ADDA


def get_colorsOfNodes(filename):
    if "gHN" in filename:
        return 'blue'
    if "gIN" in filename:
        return "red"
    if "gFN" in filename:
        return "green"
    return "gray"


def get_numberOfOrientations(filename):
    return int(filename[-4:])  # -4: e.g. _N0030


def draw_asANumberOfOrientations(ax, numOris, s11s, colors, atitle=''):
    ax.set_xscale("log")
    ax.set_title(atitle)
    for xpos, ypos, aclr in zip(numOris, s11s, colors):
        ax.scatter(xpos, ypos, color=aclr, marker='.')
    ax.set_xlabel('Nori')
    # for xpos, ypos in zip(numOris, s11s):
    #    # 0.1:arbitrary to adjust text position
    #    ax.text(xpos, ypos + 0.1, str(xpos), rotation=45.0)

PICKUP_THETA_IDX = 170  # Pick up position of the Theta (Scattring angle)

# Pickup values at a specified scattering angle
numOris = []  # Nori (Number of orientations)
Nori_s11s = []  # S11 as a function of Nori(Number of orientations)
Nori_pols = []  # Pol as a function of Nori(Number of orientations)
Nori_clrs = []  # colors of the plot
for afile in IN_FILES:
    thetas, s11s, pols = read_s11_and_polarization(afile)
    numOris += [get_numberOfOrientations(afile)]
    Nori_s11s += [s11s[PICKUP_THETA_IDX]]
    Nori_pols += [pols[PICKUP_THETA_IDX]]
    Nori_clrs += [get_colorsOfNodes(afile)]
    print(numOris[-1], Nori_s11s[-1], Nori_pols[-1], Nori_clrs[-1])

# Plot
fig = plt.figure()
ax1a = fig.add_subplot(2, 2, 1)
title = 'Phase function (%s deg)' % PICKUP_THETA_IDX
draw_asANumberOfOrientations(ax1a, numOris, Nori_s11s, Nori_clrs, title)
ax1b = fig.add_subplot(2, 2, 2)
title = 'Degree of Polarization (%s deg)' % PICKUP_THETA_IDX
draw_asANumberOfOrientations(ax1b, numOris, Nori_pols, Nori_clrs, title)

fig.tight_layout()

```

### Result

<!-- ![qiita.png](https://qiita-image-store.s3.amazonaws.com/0/32870/0b422354-c498-4cb8-94c1-8d5aad115332.png) -->

![qiita.png](https://qiita-image-store.s3.amazonaws.com/0/32870/df5cb2ad-837e-7f31-0b8a-c4636b099d52.png)


- blue: Hammersley Nodes
- red: Icosahedral Nodes
- green: Fibonacci Nodes

3つのnode setに積分精度の有意な差はなさそう。


### 似たような値のplot

```py:test_scatter_3groups_180211.ipynb
%matplotlib inline
import matplotlib.pyplot as plt
from matplotlib import cm, colors
from mpl_toolkits.mplot3d import Axes3D
from pylab import rcParams
import numpy as np
import time


rcParams['figure.figsize'] = 10, 4
rcParams['figure.dpi'] = 110


fig = plt.figure()

xas = [ 30, 60, 100, 300, 500, 1000, 1500, 2000 ]
yas = [ 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14 ]

xbs = [ 33, 66, 110, 330, 550, 1100, 1650, 2200 ]
ybs = [ 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14 ]

xcs = [ 12 ]
ycs = [ 3.14 ]


ax = fig.add_subplot(2, 2, 1)
ax.set_xscale("log")
ax.scatter(xas, yas, color='blue', marker='.')
ax.scatter(xbs, ybs, color='red', marker='.')
ax.scatter(xcs, ycs, color='green', marker='.')

```

![qiita.png](https://qiita-image-store.s3.amazonaws.com/0/32870/cd01f852-915f-3ef8-db08-cd1dee50f36d.png)


X軸が同じでY値が近い２つのグループをPlotすると、重なってしまい識別ができなくなる。
(上図のredのように)X軸をずらすとPlot上では識別はできるが、X軸が異なるため数値誤差の議論では使えない。
X軸は同じにしておいて、別の描画方法(グラフを分ける)を検討する方が良いかもしれない。