Microsoft MVP성태의 닷넷 이야기
.NET Framework: 839. C# - PLplot 색상 제어 [링크 복사], [링크+제목 복사]
조회: 9691
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 3개 있습니다.)

C# - PLplot 색상 제어

저도 확실히는 모르지만, 일단 그냥 코드 상으로 본 것만 기록을 남기려고 합니다.

우선, PLplot은 palette 개념이 있는 듯한데 기본적으로 16개 공간만 있고 다음의 코드를 통해 확인할 수 있습니다.

using (var pl = new PLStream())
{
    for (int i = 0; i < 20; i ++)
    {
        pl.gcol0(i, out int r, out int g, out int b);
        Console.WriteLine($"{i} == {r}, {g}, {b}");
    }
}

/*
0 == 0, 0, 0
1 == 255, 0, 0
2 == 255, 255, 0
3 == 0, 255, 0
4 == 127, 255, 212
5 == 255, 192, 203
6 == 245, 222, 179
7 == 190, 190, 190
8 == 165, 42, 42
9 == 0, 0, 255
10 == 138, 43, 226
11 == 0, 255, 255
12 == 64, 224, 208
13 == 255, 0, 255
14 == 250, 128, 114
15 == 255, 255, 255
16 == 0, 0, 0
... 17번 부터는 다음과 같은 식으로 오류 발생
*** PLPLOT ERROR, ABORTING OPERATION ***
plgcol0: Invalid color index: 17, aborting operation
17 == -1, -1, -1
*/

위의 컬러 값에 대한 상수 값은 다음과 같이 미리 정의되어 있습니다.

namespace PLplot
{
    public static class Color
    {
        public const int Black = 0;
        public const int Red = 1;
        public const int Yellow = 2;
        public const int Green = 3;
        public const int Aquamarine = 4;
        public const int Pink = 5;
        public const int Wheat = 6;
        public const int Grey = 7;
        public const int Brown = 8;
        public const int Blue = 9;
        public const int BlueViolet = 10;
        public const int Cyan = 11;
        public const int Turquoise = 12;
        public const int Magenta = 13;
        public const int Salmon = 14;
        public const int White = 15;
    }
}

당연히 palette 값은 수정될 수 있고, 이것을 미리 정의한 테마 파일들이 바이너리가 놓인 폴더 하위 "plplot"에 담겨 있습니다. (nuget인 경우, "%USERPROFILE%\.nuget\packages\plplot\5.13.7\runtimes\win-x64\native\plplot" 폴더)

cmap0_alternate.pal
cmap0_black_on_white.pal
cmap0_default.pal
cmap0_white_bg.pal
cmap1_blue_red.pal
cmap1_blue_yellow.pal
cmap1_default.pal
cmap1_gray.pal
cmap1_highfreq.pal
cmap1_lowfreq.pal
cmap1_radar.pal

각각의 pal 파일은 텍스트 파일로 16개의 palette 색상 값을 재정의한 RGB 값을 포함합니다. 예를 들어 "cmap0_alternate.pal" 파일은 다음과 같습니다.

16
#ffffff
#000000
#0000ff
#ff0000
#a52a2a
#fa8072
#ffc0cb
#7fffd4
#f5deb3
#40e0d0
#bebebe
#00ffff
#00ff00
#ffff00
#ff00ff
#8a2be2

그러니까 가령 pl.col0 값으로 Black 인덱스를 설정한 경우,

pl.col0(PLplot.Color.Black); // 검정색 지정

기본 palette 설정에서는 검은색으로 나오겠지만, cmap0_alternate.pal 테마를 설정한 경우에는 동일한 코드가,

pl.spal0("cmap0_alternate.pal");
pl.col0(PLplot.Color.Black);

"#ffffff" 하얀색으로 바뀌게 되는 것입니다. 참고로, 기본 palette도 "cmap0_default.pal"이름으로 저장되어 있으며 다음과 같이 빈 문자열을 주면,

pl.spal0(""); // cmap0_default.pal 선택

기본 palette이 선택됩니다. (null을 주면 System.AccessViolationException 예외가 발생합니다)




palette은 코드 중간에 바뀌는 것이 허용됩니다. 예를 들어, 기본 상태에서는 다음과 같이 검은 바탕에 빨간색 축이지만,

plplot_color_1.png

pl.init() 호출 전에 palette을 바꿔주면,

pl.spal0("cmap0_alternate.pal");
pl.init();

(테마에 재정의되었으므로) 하얀색 바탕에 검은색 축이 그려지고, 이후 다시 spal0 호출로 바꿔주면 그에 따른 색상 인덱스를 지정할 수 있습니다.

pl.spal0("cmap0_alternate.pal");
pl.init();

pl.env(xMin, xMax, yMin, yMax, AxesScale.Independent, AxisBox.BoxTicksLabelsAxes);
pl.lab("X", "Y", "Click");

char code = Symbol.Bullet;
pl.spal0(""); // 기본 palette으로 복구했으므로,
pl.col0(PLplot.Color.Blue); // Blue 인덱스의 의미에 따라 파란색 점으로 출력
pl.poin(xData, yData, code);

plplot_color_2.png

개인적인 생각으로는, PLplot.Color 상수를 사용하는 경우에는 palette을 기본 설정한 상태로 써야 혼란이 없을 것이고 만약 palette을 바꾼 상태에서 쓰고 싶다면 바뀐 테마에 맞게 상수를 새롭게 정의해서 쓰는 것이 좋을 듯합니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 5/28/2019]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... [31]  32  33  34  35  36  37  38  39  40  41  42  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
12845정성태10/6/20218099.NET Framework: 1120. C# - BufferBlock<T> 사용 예제 [5]파일 다운로드1
12844정성태10/3/20216133오류 유형: 764. MSI 설치 시 "... is accessible and not read-only." 오류 메시지
12843정성태10/3/20216593스크립트: 29. 파이썬 - fork 시 기존 클라이언트 소켓 및 스레드의 동작파일 다운로드1
12842정성태10/1/202124813오류 유형: 763. 파이썬 오류 - AttributeError: type object '...' has no attribute '...'
12841정성태10/1/20218379스크립트: 28. 모든 파이썬 프로세스에 올라오는 특별한 파일 - sitecustomize.py
12840정성태9/30/20218433.NET Framework: 1119. Entity Framework의 Join 사용 시 다중 칼럼에 대한 OR 조건 쿼리파일 다운로드1
12839정성태9/15/20219495.NET Framework: 1118. C# 11 - 제네릭 타입의 특성 적용파일 다운로드1
12838정성태9/13/20219146.NET Framework: 1117. C# - Task에 전달한 Action, Func 유형에 따라 달라지는 async/await 비동기 처리 [2]파일 다운로드1
12837정성태9/11/20218089VC++: 151. Golang - fmt.Errorf, errors.Is, errors.As 설명
12836정성태9/10/20217681Linux: 45. 리눅스 - 실행 중인 다른 프로그램의 출력을 확인하는 방법
12835정성태9/7/20218947.NET Framework: 1116. C# 10 - (15) CallerArgumentExpression 특성 추가 [2]파일 다운로드1
12834정성태9/7/20217322오류 유형: 762. Visual Studio 2019 Build Tools - 'C:\Program' is not recognized as an internal or external command, operable program or batch file.
12833정성태9/6/20216772VC++: 150. Golang - TCP client/server echo 예제 코드파일 다운로드1
12832정성태9/6/20217609VC++: 149. Golang - 인터페이스 포인터가 의미 있을까요?
12831정성태9/6/20216152VC++: 148. Golang - 채널에 따른 다중 작업 처리파일 다운로드1
12830정성태9/6/20218373오류 유형: 761. Internet Explorer에서 파일 다운로드 시 "Your current security settings do not allow this file to be downloaded." 오류
12829정성태9/5/202110022.NET Framework: 1115. C# 10 - (14) 구조체 타입에 기본 생성자 정의 가능파일 다운로드1
12828정성태9/4/20218147.NET Framework: 1114. C# 10 - (13) 단일 파일 내에 적용되는 namespace 선언파일 다운로드1
12827정성태9/4/20218129스크립트: 27. 파이썬 - 웹 페이지 데이터 수집을 위한 scrapy Crawler 사용법 요약
12826정성태9/3/202110372.NET Framework: 1113. C# 10 - (12) 문자열 보간 성능 개선 [1]파일 다운로드1
12825정성태9/3/20217932개발 환경 구성: 603. GoLand - WSL 환경과 연동
12824정성태9/2/202117009오류 유형: 760. 파이썬 tensorflow - Dst tensor is not initialized. 오류 메시지
12823정성태9/2/20216741스크립트: 26. 파이썬 - PyCharm을 이용한 fork 디버그 방법
12822정성태9/1/202111948오류 유형: 759. 파이썬 tensorflow - ValueError: Shapes (...) and (...) are incompatible [2]
12821정성태9/1/20217503.NET Framework: 1112. C# - .NET 6부터 공개된 ISpanFormattable 사용법
12820정성태9/1/20217810VC++: 147. Golang - try/catch에 대응하는 panic/recover [1]파일 다운로드1
... [31]  32  33  34  35  36  37  38  39  40  41  42  43  44  45  ...