[Matplotlib] 내가 쓰는 배경이 어두운 색일 때 matplotlib 설정

2022. 4. 27. 15:02·프로그래밍 Programming/파이썬 Python

 

나는 Jupyter notebook을 쓸 때 눈의 피로도를 낮추기 위해서 테마를 어두운 색으로 적용했다.

 

 

jupyter notebook theme를 적용하는 라이브러리를 사용해서 이렇게 했는데 문제는 plot을 그릴 때 matplotlib은 기본적으로 tick과 글씨들이 모두 검은색으로 적용이 되면서 plot이 잘 안 보이는 문제가 발생했다.

 

위의 그림처럼 된다.

그래서 두 가지 방법이 있는데,

 

1. matplotlib에서 쓰는 style 자체를 바꾸는 것

2. figure의 face color를 white로 바꾸는 것

 

 


 

1번 방법

 

그래프를 그리기 전에 다음과 같은 코드를 사용한다.

plt.style.use('seaborn')

 

use() 괄호 안에는 여러가지가 들어갈 수 있는데 'seaborn'은 그래프를 그려주는 library 중 하나인 seaborn과 거의 유사한 형태로 그려주는 스타일이다.

 

1) 'seaborn'

 

 

2) 'default'

 

'default'는 원래 기본적으로 matplotlib이 쓰는 스타일

원래 스타일을 계속 쓰고 싶다면, 그냥 그래프를 그리는 것보다는 미리 default를 설정하고 그리면 바탕을 하얗게 만들어준다.

3) 'classic'

 

'classic'은 옛날 그래프들 보면 흔히 볼 수 있는 스타일

예시 :

4) 'ggplot'

'ggplot'는 R프로그래밍에서 plot 그릴 때 사용하는 라이브러리인데 이와 유사한 스타일

 

 

 

이 스타일 외에도 다른 스타일이 있는지 확인할 수 있다.

plt.style.available

다음 코드를 입력하면 아래와 같이 사용할 수 있는 style이 나온다.

['Solarize_Light2',
 '_classic_test_patch',
 '_mpl-gallery',
 '_mpl-gallery-nogrid',
 'bmh',
 'classic',
 'dark_background',
 'fast',
 'fivethirtyeight',
 'ggplot',
 'grayscale',
 'seaborn',
 'seaborn-bright',
 'seaborn-colorblind',
 'seaborn-dark',
 'seaborn-dark-palette',
 'seaborn-darkgrid',
 'seaborn-deep',
 'seaborn-muted',
 'seaborn-notebook',
 'seaborn-paper',
 'seaborn-pastel',
 'seaborn-poster',
 'seaborn-talk',
 'seaborn-ticks',
 'seaborn-white',
 'seaborn-whitegrid',
 'tableau-colorblind10']

 

 

2번 방법

matplotlib은 그래프의 배경 색상과 바깥 배경 색상을 지정할 수 있다. 일반적으로 위의 예시 그림처럼 그래프가 그려지는 바탕은 하얀색인데 바깥 배경은 투명이므로 하얀색으로 지정해준다.

 

plt.figure(facecolor='white')

plt.plot(x,y) ...

 


 

참고 자료

https://pythonguides.com/matplotlib-change-background-color/

 

Matplotlib Change Background Color - Python Guides

In this tutorial, we will discuss the Matplotlib change background color in python. And we learn how to change the background color of the plot.

pythonguides.com

 

저작자표시 비영리 변경금지 (새창열림)

'프로그래밍 Programming > 파이썬 Python' 카테고리의 다른 글

[Python] Visual studio code에서 python 파일(.py) compile하는 방법과 exited with code=9009 에러 해결  (2) 2022.07.05
[에러기록] TypeError: Input 'y' of 'Mul' Op has type float64 that does not match type float32 of argument 'x'.  (0) 2022.06.01
파이썬에 대한 몇 가지 설명  (0) 2021.05.25
[Python] 내가 헷갈려서 기록하는 matplotlib의 subplot 그리기  (0) 2021.04.22
[Python] Numpy 라이브러리(2)  (0) 2021.03.27
'프로그래밍 Programming/파이썬 Python' 카테고리의 다른 글
  • [Python] Visual studio code에서 python 파일(.py) compile하는 방법과 exited with code=9009 에러 해결
  • [에러기록] TypeError: Input 'y' of 'Mul' Op has type float64 that does not match type float32 of argument 'x'.
  • 파이썬에 대한 몇 가지 설명
  • [Python] 내가 헷갈려서 기록하는 matplotlib의 subplot 그리기
보통의공대생
보통의공대생
수학,프로그래밍,기계항공우주 등 공부하는 기록들을 남깁니다.
  • 보통의공대생
    뛰는 놈 위에 나는 공대생
    보통의공대생
  • 전체
    오늘
    어제
    • 분류 전체보기 (460)
      • 공지 (1)
      • 영어 공부 English Study (40)
        • 텝스 TEPS (7)
        • 글 Article (21)
        • 영상 Video (10)
      • 연구 Research (99)
        • 최적화 Optimization (3)
        • 데이터과학 Data Science (7)
        • 인공지능 Artificial Intelligent (40)
        • 제어 Control (45)
      • 프로그래밍 Programming (103)
        • 매트랩 MATLAB (25)
        • 파이썬 Python (33)
        • 줄리아 Julia (2)
        • C++ (3)
        • 리눅스 우분투 Ubuntu (6)
      • 항공우주 Aeronautical engineeri.. (21)
        • 항법 Navigation (0)
        • 유도 Guidance (0)
      • 기계공학 Mechanical engineering (13)
        • 열역학 Thermodynamics (0)
        • 고체역학 Statics & Solid mechan.. (10)
        • 동역학 Dynamics (1)
        • 유체역학 Fluid Dynamics (0)
      • 수학 Mathematics (34)
        • 선형대수학 Linear Algebra (18)
        • 미분방정식 Differential Equation (3)
        • 확률및통계 Probability & Sta.. (2)
        • 미적분학 Calculus (1)
        • 복소해석학 Complex Analysis (5)
        • 실해석학 Real Analysis (0)
      • 수치해석 Numerical Analysis (21)
      • 확률 및 랜덤프로세스 Random process (2)
      • 추론 & 추정 이론 Estimation (3)
      • 기타 (26)
        • 설계 프로젝트 System Design (8)
        • 논문작성 Writing (55)
        • 세미나 Seminar (2)
        • 생산성 Productivity (3)
      • 유학 생활 Daily (7)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    옵시디언
    IEEE
    ChatGPT
    Linear algebra
    JAX
    Numerical Analysis
    WOX
    딥러닝
    수치해석
    인공지능
    논문작성법
    텝스공부
    Dear abby
    Julia
    Python
    LaTeX
    논문작성
    에러기록
    Zotero
    obsidian
    우분투
    teps
    고체역학
    텝스
    MATLAB
    pytorch
    matplotlib
    생산성
    서버
    Statics
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
보통의공대생
[Matplotlib] 내가 쓰는 배경이 어두운 색일 때 matplotlib 설정
상단으로

티스토리툴바