'Programming/python(파이썬)'에 해당되는 글 101건

  1. 2023.10.04 matplotlib
  2. 2023.10.04 pyplot
  3. 2023.03.08 python matplotlib 설치
  4. 2022.04.12 python openCV / PIL 포맷 변경
  5. 2022.04.12 파이썬 딕셔너리 변수 생성과 리턴 enumerate, zip
  6. 2022.03.15 python interactive mode
  7. 2022.03.14 python3 opencv2 checker board
  8. 2022.03.14 pdb
  9. 2022.03.04 python debug (pdb)
  10. 2022.02.25 opencv python

gnuplot을 래핑해서 만든건줄 알았는데 독립된 건가?

[링크 : https://matplotlib.org/stable/tutorials/pyplot.html]

 

500.000 points scatterplot
gnuplot:      5.171 s
matplotlib: 230.693 s

[링크 : https://stackoverflow.com/questions/911655/gnuplot-vs-matplotlib]

 

2차축 추가. y축에 대해서 주로 넣지 x 축에 넣는건 먼가 신선하네

import datetime

import matplotlib.pyplot as plt
import numpy as np

import matplotlib.dates as mdates
from matplotlib.ticker import AutoMinorLocator

fig, ax = plt.subplots(layout='constrained')
x = np.arange(0, 360, 1)
y = np.sin(2 * x * np.pi / 180)
ax.plot(x, y)
ax.set_xlabel('angle [degrees]')
ax.set_ylabel('signal')
ax.set_title('Sine wave')


def deg2rad(x):
    return x * np.pi / 180


def rad2deg(x):
    return x * 180 / np.pi


secax = ax.secondary_xaxis('top', functions=(deg2rad, rad2deg))
secax.set_xlabel('angle [rad]')
plt.show()

[링크 : https://matplotlib.org/stable/gallery/subplots_axes_and_figures/secondary_axis.html]

 

특이하게 배열로 된 값이 들어가는게 아닌, 함수를 통해서 1차축에 대해서 계산해서 2차축을 쓰는 듯?

Axes.secondary_xaxis(location, *, functions=None, **kwargs)
Axes.secondary_yaxis(location, *, functions=None, **kwargs)

functions2-tuple of func, or Transform with an inverse
If a 2-tuple of functions, the user specifies the transform function and its inverse. i.e. functions=(lambda x: 2 / x, lambda x: 2 / x) would be an reciprocal transform with a factor of 2. Both functions must accept numpy arrays as input.

The user can also directly supply a subclass of transforms.Transform so long as it has an inverse.

See Secondary Axis for examples of making these conversions.

[링크 : https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.secondary_xaxis.html#matplotlib.axes.Axes.secondary_xaxis]

[링크 : https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.secondary_yaxis.html#matplotlib.axes.Axes.secondary_yaxis]

'Programming > python(파이썬)' 카테고리의 다른 글

파이썬 가상환경  (0) 2024.01.09
pyplot legend picking  (0) 2023.10.05
pyplot  (0) 2023.10.04
python matplotlib 설치  (0) 2023.03.08
python openCV / PIL 포맷 변경  (0) 2022.04.12
Posted by 구차니

하나의 그래프에 여러개의 데이터를 한번에 그리기

import matplotlib.pyplot as plt
import numpy as np
  
# create data
x = [1,2,3,4,5]
y = [3,3,3,3,3]
  
# plot lines
plt.plot(x, y, label = "line 1", linestyle="-")
plt.plot(y, x, label = "line 2", linestyle="--")
plt.plot(x, np.sin(x), label = "curve 1", linestyle="-.")
plt.plot(x, np.cos(x), label = "curve 2", linestyle=":")
plt.legend()
plt.show()

[링크 : https://www.geeksforgeeks.org/plot-multiple-lines-in-matplotlib/]

 

'Programming > python(파이썬)' 카테고리의 다른 글

pyplot legend picking  (0) 2023.10.05
matplotlib  (0) 2023.10.04
python matplotlib 설치  (0) 2023.03.08
python openCV / PIL 포맷 변경  (0) 2022.04.12
파이썬 딕셔너리 변수 생성과 리턴 enumerate, zip  (0) 2022.04.12
Posted by 구차니

matplotlib을 이용하여 python 에서 그래프를 그리려고 하는데 그려지지 않아서 고생 -_-

그냥 설치하면 이상한(?) 에러가 발생하면서 중단되는데

나의 경우에는 jpeg 라이브러리 없다고 배쨰는 중. 그래서 libjpeg 등을 설치하고 Pillow 라는 python 패키지를 설치후

matplotlib을 설치하니 해결되었다.

 

sudo apt install libjpeg-dev zlib1g-dev
pip install Pillow

[링크 : https://stackoverflow.com/questions/44043906/the-headers-or-library-files-could-not-be-found-for-jpeg-installing-pillow-on]

pip3 install matplotlib

[링크 : https://www.zinnunkebi.com/python-modulenotfounderror-matplotlib/]

'Programming > python(파이썬)' 카테고리의 다른 글

matplotlib  (0) 2023.10.04
pyplot  (0) 2023.10.04
python openCV / PIL 포맷 변경  (0) 2022.04.12
파이썬 딕셔너리 변수 생성과 리턴 enumerate, zip  (0) 2022.04.12
python interactive mode  (0) 2022.03.15
Posted by 구차니

필요한 건 openCV로 받아 PIL로 변환하는거라 아래것만 테스트 해봄

import cv2
from PIL

opencv_image=cv2.imread(".\\learning_python.png")
color_coverted = cv2.cvtColor(opencv_image, cv2.COLOR_BGR2RGB)
pil_image=PIL.Image.fromarray(color_coverted)

[링크 : https://www.zinnunkebi.com/python-opencv-pil-convert/]

'Programming > python(파이썬)' 카테고리의 다른 글

pyplot  (0) 2023.10.04
python matplotlib 설치  (0) 2023.03.08
파이썬 딕셔너리 변수 생성과 리턴 enumerate, zip  (0) 2022.04.12
python interactive mode  (0) 2022.03.15
python3 opencv2 checker board  (0) 2022.03.14
Posted by 구차니

발견하게 된 생소한 문법은 아래와 같은데..

enumerate() 함수를 이용해 이름 목록을 열거하고 인덱스와 함께 

name(키) 와 outputs 라는 구조를 쌍으로 묶어 딕셔너리로 돌려준다.

return {name: outputs[i] for i, name in enumerate(self.output_names)}

 

def create_dict():
    ''' Function to return dict '''
    return {i:str(i) for i in range(10)}
numbers = create_dict()
print(numbers)
# {0: '0', 1: '1', 2: '2', 3: '3', 4: '4', 5: '5', 6: '6', 7: '7', 8: '8', 9: '9'}

[링크 : https://blog.finxter.com/python-return-dictionary-from-function/]

 

enumerate() 는 내용과 인덱스를 같이 돌려주고 start 키워드를 이용해 시작 인덱스를 0이 아닌 것으로 설정이 가능하다.

>>> for entry in enumerate(['A', 'B', 'C']):
...     print(entry)
...
(0, 'A')
(1, 'B')
(2, 'C')

[링크 : https://www.daleseo.com/python-enumerate/]

 

enumerate()와 유사하게 두개의 배열을 하나의 쌍으로 묶어주는 함수

>>> numbers = [1, 2, 3]
>>> letters = ["A", "B", "C"]
>>> for pair in zip(numbers, letters):
...     print(pair)
...
(1, 'A')
(2, 'B')
(3, 'C')

[링크 : https://www.daleseo.com/python-zip/]

'Programming > python(파이썬)' 카테고리의 다른 글

python matplotlib 설치  (0) 2023.03.08
python openCV / PIL 포맷 변경  (0) 2022.04.12
python interactive mode  (0) 2022.03.15
python3 opencv2 checker board  (0) 2022.03.14
pdb  (0) 2022.03.14
Posted by 구차니

별건 아니고 그냥

python 실행해서 뜨는 프롬프트에서 입력해서 실행하는 모드

 

[링크 : https://en.m.wikibooks.org/wiki/Python_Programming/Interactive_mode]

[링크 : https://stackabuse.com/python-programming-in-interactive-vs-script-mode/]

 

'Programming > python(파이썬)' 카테고리의 다른 글

python openCV / PIL 포맷 변경  (0) 2022.04.12
파이썬 딕셔너리 변수 생성과 리턴 enumerate, zip  (0) 2022.04.12
python3 opencv2 checker board  (0) 2022.03.14
pdb  (0) 2022.03.14
python debug (pdb)  (0) 2022.03.04
Posted by 구차니

나중에 따라해.. 봐야지 ㅠㅠ

 

[링크 : http://www.gisdeveloper.co.kr/?p=6868]

'Programming > python(파이썬)' 카테고리의 다른 글

파이썬 딕셔너리 변수 생성과 리턴 enumerate, zip  (0) 2022.04.12
python interactive mode  (0) 2022.03.15
pdb  (0) 2022.03.14
python debug (pdb)  (0) 2022.03.04
opencv python  (0) 2022.02.25
Posted by 구차니

pdb

 

$ pdb chcker.py 
> /home/minimonk/src/py/chcker.py(1)<module>()
-> import numpy as np
(Pdb) run
Restarting chcker.py with arguments:

> /home/minimonk/src/py/chcker.py(1)<module>()
-> import numpy as np
(Pdb) list
  1  -> import numpy as np
  2   import cv2
  3   import glob
  4   # termination criteria
  5   criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
  6   # prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0)
  7   objp = np.zeros((6*7,3), np.float32)
  8   objp[:,:2] = np.mgrid[0:7,0:6].T.reshape(-1,2)
  9   # Arrays to store object points and image points from all the images.
 10   objpoints = [] # 3d point in real world space
 11   imgpoints = [] # 2d points in image plane.
(Pdb) n
> /home/minimonk/src/py/chcker.py(2)<module>()
-> import cv2
(Pdb) n
ImportError: 'No module named cv2'
> /home/minimonk/src/py/chcker.py(2)<module>()
-> import cv2
(Pdb) q

 

$ whereis pdb
pdb: /usr/bin/pdb2.7 /usr/bin/pdb /usr/bin/pdb3.6 /usr/share/man/man1/pdb.1.gz

$ ls -al /usr/bin/pdb*
lrwxrwxrwx 1 root root  6  4월 16  2018 /usr/bin/pdb -> pdb2.7
lrwxrwxrwx 1 root root 23  2월 28  2021 /usr/bin/pdb2.7 -> ../lib/python2.7/pdb.py
lrwxrwxrwx 1 root root  6  1월 28 12:37 /usr/bin/pdb3 -> pdb3.6
lrwxrwxrwx 1 root root 23 12월  9 06:08 /usr/bin/pdb3.6 -> ../lib/python3.6/pdb.py

$ ls -al /usr/lib/python3.
python3.6/ python3.7/ python3.8/ 

$ ls -al /usr/lib/python3.6/pdb.py 
-rwxr-xr-x 1 root root 61310 12월  9 06:08 /usr/lib/python3.6/pdb.py

[링크 : https://docs.python.org/ko/3.7/library/pdb.html]

'Programming > python(파이썬)' 카테고리의 다른 글

python interactive mode  (0) 2022.03.15
python3 opencv2 checker board  (0) 2022.03.14
python debug (pdb)  (0) 2022.03.04
opencv python  (0) 2022.02.25
python / opencv mouse event  (0) 2022.02.25
Posted by 구차니

파이썬을 인터프리터로 생각해서 쓰다보니

희한하게 함수만 되면 어떻게 해야 할지 감이 안왔는데 pdb를 이용하면 단계별로 실행할 수 있어서

함수 자체를 디버깅 할 수 있겠다 싶어서 한번 시도해볼 만 할 듯.

 

[링크 : http://pythonstudy.xyz/python/article/505-Python-디버깅-PDB]

'Programming > python(파이썬)' 카테고리의 다른 글

python3 opencv2 checker board  (0) 2022.03.14
pdb  (0) 2022.03.14
opencv python  (0) 2022.02.25
python / opencv mouse event  (0) 2022.02.25
python op overload magic method  (0) 2021.06.14
Posted by 구차니

파이썬에서  openCV highgui를 전체 화면으로 돌려보기

 

[링크 : https://www.javatpoint.com/opencv-mouse-event]

 

full screen (fail)

[링크 : https://gist.github.com/ronekko/dc3747211543165108b11073f929b85e]

 

cv2.waitkey ord

[링크 : https://stackoverflow.com/questions/14494101/using-other-keys-for-the-waitkey-function-of-opencv]

'Programming > python(파이썬)' 카테고리의 다른 글

pdb  (0) 2022.03.14
python debug (pdb)  (0) 2022.03.04
python / opencv mouse event  (0) 2022.02.25
python op overload magic method  (0) 2021.06.14
pythonpath  (0) 2021.04.16
Posted by 구차니