반응형
반응형

일이 조금 잘되어 주위 사람들이 추어올리면 금세 마음이 해이해져
마치 실이 끊어진 연처럼 한없이 붕붕 떠다니는 게 우리 인간의 본성이다.
인생의 길을 잘못 내딛는 원흉이 되는 것은 실패나 좌절이 아니었다.
사람을 몰락시키는 것은 늘 성공과 칭찬이었다.
겸허한 마음은 부적과 같다.
- 이나모리 가즈오, ‘왜 리더인가’에서


판토하가 쓴 칠극에는 “큰 덕을 지닌 이들은 자신을 헐뜯는 말을 듣는 것을
세상 사람들이 칭찬해 기리는 말을 듣는 것보다 기뻐했다.
지혜로운 사람이 귀를 기울여 칭찬하는 말을 들으면 어리석어지고,
듣고 나서 혼자 기뻐하면 미치광이가 된다.”는 경구가 나옵니다.
사람을 몰락시키는 것은 늘 성공과 칭찬이었습니다.

반응형
반응형

[python] mpld3를 이용해서 python의 그림을 웹에 올려보자.https://frhyme.github.io/python-libs/plt_mpld3/#matplotlibpyplot%EB%A1%9C-%EA%B7%B8%EB%A6%B0-%EA%B7%B8%EB%A6%BC%EC%9D%84-%ED%8E%B8%ED%95%98%EA%B2%8C-html%EB%A1%9C-%EB%B0%94%EA%BE%B8%EC%9E%90

 

mpld3를 이용해서 python의 그림을 웹에 올려보자.

matplotlib.pyplot로 그린 그림을 편하게 html로 바꾸자.

frhyme.github.io

 

matplotlib.pyplot로 그린 그림을 편하게 html로 바꾸자.Permalink

  • 파이썬으로 코딩하는 사람들은 시각화할때 대부분 matplotlib를 사용할 것이라고 생각합니다. 특히 matplotlib는 jupyter notebook과 붙으면 매우 굉-장해집니다. 그림을 바로 그리고 고치고, 다시 그리고 괜찮으면 저장, 하는 등의 작업을 수행하게 되죠.
  • 아무튼, 그냥 개인이 저장해서 처리한다면 아무 문제가 없지만, 이걸 웹에 뿌려주고 싶을 때는 이게 생각처럼 되지 않습니다. 그냥 그림으로 만들어서 전달해도 되지만, 그럴 경우에는 화면의 비율등에 따라서 깨질 수 있고, 이는 글자크기, 간격 등에 모두 영향을 미치게 되니까 아주 엉망인 그림이 만들어질 가능성이 높습니다.
    • 물론 svg파일로 만들어서 전달하는 것도 방법입니다만, 이 경우에도 어느 정도의 문제가 발생할 수는 있습니다.
  • 가장 좋은 선택지는, 웹상의 요소로 변환하는 것이 될것이고, 그 방법중 하나로 mpld3와 같은 라이브러리를 사용해서 처리할 수 있습니다.

what is mpld3?Permalink

The mpld3 project brings together Matplotlib, the popular Python-based graphing library, and D3js, the popular JavaScript library for creating interactive data visualizations for the web. The result is a simple API for exporting your matplotlib graphics to HTML code which can be used within the browser, within standard web pages, blogs, or tools such as the IPython notebook.

  • 공식 홈페이지에서 가져왔습니다. 간단히 정리하면, mpld3는 매트플롯립과 d3js를 사용해서 웹의 인터랙티브 데이터 시각화 를 가능하도록 만드는 것이 목적이라고 하네요. 간단하게, matpllitb의 그래픽을 html코드로(코드를 뜯어보면, 사실 거의 d3js 코드입니다만), 변환해줍니다. 이걸 가지고, 차트 같은 것을 좀 더 편하게 변환할 수 있겠죠.

do it.Permalink

  • 다음처럼 figure를 만들고, 그 figure를 html로 내뱉으면 됩니다.
    • html을 저장하든(save_html), 결과를 스트링으로 가져오든 뭘하든 간에 맥에서는 잘 작동하지 않습니다.
!pip install mpld3

import json
import mpld3
import matplotlib.pyplot as plt

f = plt.figure()
plt.plot([1,2,3], [4,5,6])

print(mpld3.fig_to_html(f, figid='THIS_IS_FIGID'))

  • 아래처럼 html 페이지로 만들어집니다.
<style>

</style>

<div id="THIS_IS_FIGID"></div>
<script>
function mpld3_load_lib(url, callback){
  var s = document.createElement('script');
  s.src = url;
  s.async = true;
  s.onreadystatechange = s.onload = callback;
  s.onerror = function(){console.warn("failed to load library " + url);};
  document.getElementsByTagName("head")[0].appendChild(s);
}

if(typeof(mpld3) !== "undefined" && mpld3._mpld3IsLoaded){
   // already loaded: just create the figure
   !function(mpld3){
       
       mpld3.draw_figure("THIS_IS_FIGID", {"width": 576.0, "height": 396.0, "axes": [{"bbox": [0.125, 0.125, 0.775, 0.755], "xlim": [0.9, 3.1], "ylim": [3.9, 6.1], "xdomain": [0.9, 3.1], "ydomain": [3.9, 6.1], "xscale": "linear", "yscale": "linear", "axes": [{"position": "bottom", "nticks": 11, "tickvalues": null, "tickformat": null, "scale": "linear", "fontsize": 10.0, "grid": {"gridOn": true, "color": "#FFFFFF", "dasharray": "none", "alpha": 1.0}, "visible": true}, {"position": "left", "nticks": 11, "tickvalues": null, "tickformat": null, "scale": "linear", "fontsize": 10.0, "grid": {"gridOn": true, "color": "#FFFFFF", "dasharray": "none", "alpha": 1.0}, "visible": true}], "axesbg": "#EAEAF2", "axesbgalpha": null, "zoomable": true, "id": "el149140466966796328", "lines": [{"data": "data01", "xindex": 0, "yindex": 1, "coordinates": "data", "id": "el149140466967383568", "color": "#4C72B0", "linewidth": 1.75, "dasharray": "none", "alpha": 1, "zorder": 2, "drawstyle": "default"}], "paths": [], "markers": [], "texts": [], "collections": [], "images": [], "sharex": [], "sharey": []}], "data": {"data01": [[1.0, 4.0], [2.0, 5.0], [3.0, 6.0]]}, "id": "el149140466979442984", "plugins": [{"type": "reset"}, {"type": "zoom", "button": true, "enabled": false}, {"type": "boxzoom", "button": true, "enabled": false}]});
   }(mpld3);
}else if(typeof define === "function" && define.amd){
   // require.js is available: use it to load d3/mpld3
   require.config({paths: {d3: "https://mpld3.github.io/js/d3.v3.min"}});
   require(["d3"], function(d3){
      window.d3 = d3;
      mpld3_load_lib("https://mpld3.github.io/js/mpld3.v0.3.js", function(){
         
         mpld3.draw_figure("THIS_IS_FIGID", {"width": 576.0, "height": 396.0, "axes": [{"bbox": [0.125, 0.125, 0.775, 0.755], "xlim": [0.9, 3.1], "ylim": [3.9, 6.1], "xdomain": [0.9, 3.1], "ydomain": [3.9, 6.1], "xscale": "linear", "yscale": "linear", "axes": [{"position": "bottom", "nticks": 11, "tickvalues": null, "tickformat": null, "scale": "linear", "fontsize": 10.0, "grid": {"gridOn": true, "color": "#FFFFFF", "dasharray": "none", "alpha": 1.0}, "visible": true}, {"position": "left", "nticks": 11, "tickvalues": null, "tickformat": null, "scale": "linear", "fontsize": 10.0, "grid": {"gridOn": true, "color": "#FFFFFF", "dasharray": "none", "alpha": 1.0}, "visible": true}], "axesbg": "#EAEAF2", "axesbgalpha": null, "zoomable": true, "id": "el149140466966796328", "lines": [{"data": "data01", "xindex": 0, "yindex": 1, "coordinates": "data", "id": "el149140466967383568", "color": "#4C72B0", "linewidth": 1.75, "dasharray": "none", "alpha": 1, "zorder": 2, "drawstyle": "default"}], "paths": [], "markers": [], "texts": [], "collections": [], "images": [], "sharex": [], "sharey": []}], "data": {"data01": [[1.0, 4.0], [2.0, 5.0], [3.0, 6.0]]}, "id": "el149140466979442984", "plugins": [{"type": "reset"}, {"type": "zoom", "button": true, "enabled": false}, {"type": "boxzoom", "button": true, "enabled": false}]});
      });
    });
}else{
    // require.js not available: dynamically load d3 & mpld3
    mpld3_load_lib("https://mpld3.github.io/js/d3.v3.min.js", function(){
         mpld3_load_lib("https://mpld3.github.io/js/mpld3.v0.3.js", function(){
                 
                 mpld3.draw_figure("THIS_IS_FIGID", {"width": 576.0, "height": 396.0, "axes": [{"bbox": [0.125, 0.125, 0.775, 0.755], "xlim": [0.9, 3.1], "ylim": [3.9, 6.1], "xdomain": [0.9, 3.1], "ydomain": [3.9, 6.1], "xscale": "linear", "yscale": "linear", "axes": [{"position": "bottom", "nticks": 11, "tickvalues": null, "tickformat": null, "scale": "linear", "fontsize": 10.0, "grid": {"gridOn": true, "color": "#FFFFFF", "dasharray": "none", "alpha": 1.0}, "visible": true}, {"position": "left", "nticks": 11, "tickvalues": null, "tickformat": null, "scale": "linear", "fontsize": 10.0, "grid": {"gridOn": true, "color": "#FFFFFF", "dasharray": "none", "alpha": 1.0}, "visible": true}], "axesbg": "#EAEAF2", "axesbgalpha": null, "zoomable": true, "id": "el149140466966796328", "lines": [{"data": "data01", "xindex": 0, "yindex": 1, "coordinates": "data", "id": "el149140466967383568", "color": "#4C72B0", "linewidth": 1.75, "dasharray": "none", "alpha": 1, "zorder": 2, "drawstyle": "default"}], "paths": [], "markers": [], "texts": [], "collections": [], "images": [], "sharex": [], "sharey": []}], "data": {"data01": [[1.0, 4.0], [2.0, 5.0], [3.0, 6.0]]}, "id": "el149140466979442984", "plugins": [{"type": "reset"}, {"type": "zoom", "button": true, "enabled": false}, {"type": "boxzoom", "button": true, "enabled": false}]});
            })
         });
}
</script>

wrap-upPermalink

  • mpld3 example gallery에 들어가면 그 외에도 다양한 예제들이 있습니다만, 이걸 다 정확하게 이해하려면 d3js를 잘 알아야 하는 것 같습니다.
  • 또한 아쉽게도 networkx를 통해서 그린 그림에 대해서는 잘 만들어주지 않습니다. 결국 이건 다른 라이브러리를 사용해서 변환하는 쪽으로 생각해야 할 것 같아요. 정 안되면, 그냥 svg로 만들어서 뿌려주는 것이 가장 효과적인 것 같습니다.

 

 

반응형
반응형

[python] How to write to an HTML file in Python

https://www.kite.com/python/answers/how-to-write-to-an-html-file-in-python

 

Kite - Free AI Coding Assistant and Code Auto-Complete Plugin

Code faster with Kite’s AI-powered autocomplete plugin for over 16 programming languages and 16 IDEs, featuring Multi-Line Completions. Works 100% locally.

www.kite.com

USE open() AND file.write() TO WRITE TO AN HTML FILE

Use open(file, mode) with mode as "w" to create a new HTML file file or write to an existing one. Use file.write(data) to write data to the file. Use file.close() to close the file after writing.

text = '''
<html>
    <body>
        <h1>Heading</h1>
    </body>
</html>
'''
file = open("sample.html","w")
file.write(text)
file.close()
SAMPLE.HTML
<html>
    <body>
        <h1>Heading</h1>
    </body>
</html>
반응형
반응형

mpld3 - Bringing Matplotlib to the Browser

https://mpld3.github.io/install.html

 

Installing mpld3 — Bringing Matplotlib to the Browser

Dependencies The mpld3 package is compatible with Python versions 2.6, 2.7, 3.3, and 3.4. It requires matplotlib version 1.3+ and jinja2 version 2.7+. Optionally, mpld3 can be used within the IPython notebook, and requires IPython version 1.0+, and prefera

mpld3.github.io

 mpld3는 매트플롯립과 d3js를 사용해서 웹의 인터랙티브 데이터 시각화 를 가능하도록 만드는 것이 목적이라고 하네요. 간단하게, matpllitb의 그래픽을 html코드로(코드를 뜯어보면, 사실 거의 d3js 코드입니다만), 변환해줍니다. 이걸 가지고, 차트 같은 것을 좀 더 편하게 변환할 수 있겠죠.

https://anaconda.org/conda-forge/mpld3

Installers

Info: This package contains files in non-standard labels.

conda install 

  •  linux-64  v0.3
  •  win-32  v0.3
  •    noarch  v0.5.7
  •  osx-64  v0.3
  •  win-64  v0.3
To install this package with conda run one of the following:
conda install -c conda-forge mpld3
conda install -c conda-forge/label/gcc7 mpld3
conda install -c conda-forge/label/cf201901 mpld3
conda install -c conda-forge/label/cf202003 mpld3
반응형
반응형

데이터 리터러시( Data literacy )는 데이터 를 정보 로 읽고, 이해하고, 생성하고, 전달할 수 있는 능력 입니다. 일반 개념으로서의 문해력 과 마찬가지로 데이터 문해력은 데이터 작업과 관련된 역량 에 중점을 둡니다. 그러나 데이터를 읽고 이해하는 것과 관련된 특정 기술이 필요하기 때문에 텍스트를 읽는 능력과 유사하지 않습니다. 

 

리터러시(literacy)는 글을 읽고 해독하는 능력을 의미한다. 데이터 리터러시는 데이터를 목적에 맞게 활용하는 데이터 해석 능력을 말한다. 여기서의 데이터는 고도의 처리 기술이 필요한 빅데이터에서 단순 수치 등도 포함한다. 수많은 데이터가 쏟아지는 상황에서 데이터에 담겨있는 의미를 파악하여 의미를 파악해 내는 능력은 데이터 활용 과정 전반에 필요한 역량이다. 빅데이터 시대에 데이터 리터러시는 개인에게도 필요한 능력이며, 데이터 수집 역량, 관리 역량, 가공 및 분석 역량, 시각화 역량, 기획 역량 등이 데이터를 활용하는 능력이다.

 

 

데이터 수집  데이터 공유 가 일상화되고 데이터 분석  빅 데이터 가 뉴스, 비즈니스, [2] 정부 [3] 및 사회 에서 일반적인 아이디어가 됨에 따라 [4] 학생, 시민 및 독자에게 점점 더 중요해지고 있습니다. 데이터 활용 능력이 있습니다. 이 개념은 일반적으로 자동화된 수단을 통한 데이터 분석과 결과의 해석 및 적용과 관련된 데이터 과학과 관련이 있습니다. [5]

데이터 리터러시(Data literacy)는 그래프와 차트를 읽고 데이터에서 결론을 도출하는 능력을 포함하여 데이터의 의미를 이해하는 것을 포함하기 때문에 통계 리터러시 와 구별됩니다 . [6] 한편, 통계적 소양은 그래프, 표, 진술, 설문조사, 연구와 같은 "일상적인 매체에서 요약 통계를 읽고 해석하는 능력"을 의미한다. [6]

 

정보를 찾고 사용하기 위한 가이드로서 사서 는 학생과 연구원을 위한 데이터 활용 능력에 대한 워크샵을 이끌고 자신의 데이터 활용 능력을 개발하기 위해 노력합니다. [7]

기관 및 학문 분야에 걸쳐 도서관 교육 프로그램에서 적용 가능한 공통 참조 프레임워크로 사용할 수 있는 일련의 핵심 역량 및 내용이 제안되었습니다. [8]

사서가 만든 리소스에는 MIT 의 데이터 관리 및 출판 자습서, EDINA 연구 데이터 관리 교육(MANTRA), 에딘버러 대학의 데이터 라이브러리 및 미네소타 대학 도서관의 구조 엔지니어를 위한 데이터 관리 과정이 있습니다.

 

반응형
반응형

 

park_nohae #박노해 #걷는독서

아이들에겐 혼자만의
비밀스런 시간이 필요하다
자기 안에 신성이 깨어나는
별의 시간이 필요하다

Children need their own private time,
the time of the stars to awaken
the living divinity within them.

- 박노해, 『내 작은 방』
Park Nohae, 『My Dear Little Room』

반응형

+ Recent posts