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

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

이것저것 조사해보는데

무식하지만 가장 확실한(?) docker로 버전별로 혹은 프로젝트 별로 생성하는 것부터

python 에서 제공하는 venv

venv를 확장해서 사용하는 virtualenv

그리고 conda 정도로 정리되는 듯.

 

 

conda

[링크 : https://m.blog.naver.com/jonghong0316/221683053696]

 

virtualenv, venv

[링크 : https://jaemunbro.medium.com/python-virtualenv-venv-설정-aaf0e7c2d24e]

 

conda, venv

[링크 : https://yongeekd01.tistory.com/39]

 

venv, pipenv, conda, docker(이걸.. 가상이라고 하긴 해야 하는데.. 해줘야 하는거 맞....나?)

[링크 : https://dining-developer.tistory.com/21]

 

virtualenv, pyenv, pipenv

[링크 : https://jinwoo1990.github.io/dev-wiki/python-concept-3/]

 

+

conda - Conda provides package, dependency, and environment management for any language.

파이썬 전용이 아닌가?

[링크 : https://docs.conda.io/en/latest/]

[링크 : https://anaconda.org/]

[링크 : https://anaconda.org/anaconda/conda]

 

+

virtualenv

is slower (by not having the app-data seed method),
is not as extendable,
cannot create virtual environments for arbitrarily installed python versions (and automatically discover these),
is not upgrade-able via pip,
does not have as rich programmatic API (describe virtual environments without creating them).

[링크 : https://virtualenv.pypa.io/en/latest/]

 

+

venv

[링크 : https://docs.python.org/3/library/venv.html] 3.12.1

 

venv는 3.7 이후부터 사용이 가능한 것으로 보임. 즉, 버전별로 호환성은 없을 가능성이 있음

pyvenv 스크립트는 파이썬 3.6 에서 폐지되었고, 가상 환경이 어떤 파이썬 인터프리터를 기반으로 하는지에 대한 잠재적인 혼동을 방지하기 위해 python3 -m venv를 사용합니다.

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

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

파이썬 소켓 예제  (0) 2024.01.17
ipython notebook -> jupyter notebook  (0) 2024.01.11
pyplot legend picking  (0) 2023.10.05
matplotlib  (0) 2023.10.04
pyplot  (0) 2023.10.04
Posted by 구차니

이 선이 머다~ 라고 써있는데 legend인데

거기 클릭하면 선이 보이고 안보이고 하는 기능을 picking이라고 적어 놓은듯

 

우측 상단에 1 Hz / 2 Hz가 legend인데

레전드 내의 파란색 선을 아~~~주 잘 골라서 클릭하면

 

아래처럼 사라진다.

[링크 : https://matplotlib.org/stable/gallery/event_handling/legend_picking.html]

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

ipython notebook -> jupyter notebook  (0) 2024.01.11
파이썬 가상환경  (0) 2024.01.09
matplotlib  (0) 2023.10.04
pyplot  (0) 2023.10.04
python matplotlib 설치  (0) 2023.03.08
Posted by 구차니

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
python3 opencv2 checker board  (0) 2022.03.14
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
python3 opencv2 checker board  (0) 2022.03.14
pdb  (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
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(파이썬)' 카테고리의 다른 글

python openCV / PIL 포맷 변경  (0) 2022.04.12
파이썬 딕셔너리 변수 생성과 리턴 enumerate, zip  (0) 2022.04.12
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(파이썬)' 카테고리의 다른 글

파이썬 딕셔너리 변수 생성과 리턴 enumerate, zip  (0) 2022.04.12
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 구차니