본문 바로가기

import9.4

Python twiny()와 함께 보조 축을 사용하는 방법: 범례에 추가하는 방법, Secondary axis with twinx(): how to add to legend 질문 저는 twinx()를 사용하여 두 개의 y-축이 있는 플롯이 있습니다. 또한 라인에 레이블을 지정하고 legend()를 사용하여 이를 표시하려고하지만 레전드에서 한 축의 레이블 만 얻을 수 있습니다: import numpy as np import matplotlib.pyplot as plt from matplotlib import rc rc('mathtext', default='regular') fig = plt.figure() ax = fig.add_subplot(111) ax.plot(time, Swdown, '-', label = 'Swdown') ax.plot(time, Rn, '-', label = 'Rn') ax2 = ax.twinx() ax2.plot(time, temp, '-r', l.. 2023. 11. 13.
Python 파이썬에서 XML을 예쁘게 출력하기, Pretty printing XML in Python 질문 파이썬에서 XML을 예쁘게 출력하는 가장 좋은 방법(또는 다양한 방법)은 무엇인가요? 답변 import xml.dom.minidom dom = xml.dom.minidom.parse(xml_fname) # 또는 xml.dom.minidom.parseString(xml_string) pretty_xml_as_string = dom.toprettyxml() 2023. 10. 12.
Python fig.add_subplot(111)에서 인자 argument는 무엇을 의미합니까?, What does the argument mean in fig.add_subplot(111)? 질문 가끔 이런 코드를 만나게 됩니다: import matplotlib.pyplot as plt x = [1, 2, 3, 4, 5] y = [1, 4, 9, 16, 25] fig = plt.figure() fig.add_subplot(111) plt.scatter(x, y) plt.show() 이 코드는 다음과 같은 결과를 생성합니다: 저는 문서를 열심히 읽어봤지만 111에 대한 설명을 찾을 수 없습니다. 가끔은 212를 볼 수도 있습니다. fig.add_subplot()의 인자는 무엇을 의미하는 건가요? 답변 다음 사진으로 가장 잘 설명될 것 같습니다: 위의 내용을 초기화하려면 다음을 입력해야 합니다: import matplotlib.pyplot as plt fig = plt.figure() fig.a.. 2023. 9. 15.
Python 파이썬에서 파일을 압축 해제하기, Unzipping files in Python 질문 저는 zipfile 문서를 읽었지만, 파일을 압축 해제하는 방법은 이해할 수 없었습니다. 오직 파일을 압축하는 방법만 알려주고 있었죠. 어떻게 하면 zip 파일의 모든 내용을 동일한 디렉토리에 압축 해제할 수 있을까요? 답변 import zipfile with zipfile.ZipFile(path_to_zip_file, 'r') as zip_ref: zip_ref.extractall(directory_to_extract_to) 그게 대부분이에요! 2023. 6. 30.