Plot

Matplotlib 사용법 저장#

Cheatsheets

How-to

rcParams

  • matplotlib.pyplot의 hist나 seaborn의 kdeplot의 Density가 1을 넘어 나올 경우에는 Plot의 문제 보다는 data(numpy data?)가 plot package로 넘어갈 때 스케일 때문에 문제가 발생하는 것 같다. 이를 확인하기 위해 numpy.histogram을 확인하면 된다.
counts, bins = np.histogram(data, bins=100, range=(0, 1), density=True)
np.sum(counts) >> 100.0 
plt.plot([i*0.01 for i in range(0, 100)], counts*0.01))
np.diff()?

density? or probability density?#

Histograms and Density Plots in Python#

Can a probability distribution value exceeding 1 be OK?#

boxplot#

fig, axes = plt.subplots(14, 1, figsize=[5, 20]) ##
fig.tight_layout()

for j in range(14):
    i = float_data[:, j]
    axes[j].plot(range(len(i)), i)
    # axes[j].title(header[j])

```python
>>> a = numpy.array([0, 3, 0, 1, 0, 1, 2, 1, 0, 0, 0, 0, 1, 3, 4])
>>> unique, counts = numpy.unique(a, return_counts=True)
>>> dict(zip(unique, counts))
{0: 7, 1: 4, 2: 1, 3: 2, 4: 1}

>>> y = np.array([1, 2, 2, 2, 2, 0, 2, 3, 3, 3, 0, 0, 2, 2, 0])
>>> np.count_nonzero(y == 1)
1
>>> np.count_nonzero(y == 2)
7
>>> np.count_nonzero(y == 3)
3

Tips#

regression line#

from numpy.polynomial.polynomial import polyfit

# Fit with polyfit
b, m = polyfit(x, y, 1)

plt.plot(x, y, '.')
plt.plot(x, b + m * x, '-')
plt.show()