Microsoft MVP성태의 닷넷 이야기
.NET Framework: 839. C# - PLplot 색상 제어 [링크 복사], [링크+제목 복사],
조회: 10053
글쓴 사람
정성태 (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

비밀번호

댓글 작성자
 




... 61  62  63  64  65  66  67  68  69  70  71  [72]  73  74  75  ...
NoWriterDateCnt.TitleFile(s)
11844정성태3/14/201915111개발 환경 구성: 434. Visual Studio 2019 - 리눅스 프로젝트를 이용한 공유/실행(so/out) 프로그램 개발 환경 설정 [1]파일 다운로드1
11843정성태3/14/201910856기타: 75. MSDN 웹 사이트를 기본으로 영문 페이지로 열고 싶다면?
11842정성태3/13/201910267개발 환경 구성: 433. 마이크로소프트의 CoreCLR 프로파일러 예제를 Visual Studio CMake로 빌드하는 방법 [1]파일 다운로드1
11841정성태3/13/201910229VS.NET IDE: 132. Visual Studio 2019 - CMake의 컴파일러를 기본 g++에서 clang++로 변경
11840정성태3/13/201911335오류 유형: 526. 윈도우 10 Ubuntu App 환경에서는 USB 외장 하드 접근 불가
11839정성태3/12/201914105디버깅 기술: 124. .NET Core 웹 앱을 호스팅하는 Azure App Services의 프로세스 메모리 덤프 및 windbg 분석 개요 [3]
11838정성태3/7/201916851.NET Framework: 811. (번역글) .NET Internals Cookbook Part 1 - Exceptions, filters and corrupted processes [1]파일 다운로드1
11837정성태3/6/201926567기타: 74. 도서: 시작하세요! C# 7.3 프로그래밍 [10]
11836정성태3/5/201914408오류 유형: 525. Visual Studio 2019 Preview 4/RC - C# 8.0 Missing compiler required member 'System.Range..ctor' [1]
11835정성태3/5/201914180.NET Framework: 810. C# 8.0의 Index/Range 연산자를 .NET Framework에서 사용하는 방법 및 비동기 스트림의 컴파일 방법 [3]파일 다운로드1
11834정성태3/4/201913070개발 환경 구성: 432. Visual Studio 없이 최신 C# (8.0) 컴파일러를 사용하는 방법
11833정성태3/4/201913833개발 환경 구성: 431. Visual Studio 2019 - CMake를 이용한 공유/실행(so/out) 리눅스 프로젝트 설정파일 다운로드1
11832정성태3/4/201910853오류 유형: 524. Visual Studio CMake - rsync: connection unexpectedly closed
11831정성태3/4/201910452오류 유형: 523. Visual Studio 2019 - 새 창으로 뜬 윈도우를 닫을 때 비정상 종료
11830정성태2/26/201910243오류 유형: 522. 이벤트 로그 - Error opening event log file State. Log will not be processed. Return code from OpenEventLog is 87.
11829정성태2/26/201912142개발 환경 구성: 430. 마이크로소프트의 CoreCLR 프로파일러 예제 빌드 방법 - 리눅스 환경 [1]
11828정성태2/26/201918549개발 환경 구성: 429. Component Services 관리자의 RuntimeBroker 설정이 2개 있는 경우 [8]
11827정성태2/26/201912455오류 유형: 521. Visual Studio - Could not start the 'rsync' command on the remote host, please install it using your system package manager.
11826정성태2/26/201912341오류 유형: 520. 우분투에 .NET Core SDK 설치 시 패키지 의존성 오류
11825정성태2/25/201917204개발 환경 구성: 428. Visual Studio 2019 - CMake를 이용한 리눅스 빌드 환경 설정 [1]
11824정성태2/25/201912000오류 유형: 519. The SNMP Service encountered an error while accessing the registry key SYSTEM\CurrentControlSet\Services\SNMP\Parameters\TrapConfiguration. [1]
11823정성태2/21/201913498오류 유형: 518. IIS 관리 콘솔이 뜨지 않는 문제
11822정성태2/20/201911632오류 유형: 517. docker에 설치한 MongoDB 서버로 연결이 안 되는 경우
11821정성태2/20/201912085오류 유형: 516. Visual Studio 2019 - This extension uses deprecated APIs and is at risk of not functioning in a future VS update. [1]
11820정성태2/20/201915229오류 유형: 515. 윈도우 10 1809 업데이트 후 "User Profiles Service" 1534 경고 발생
11819정성태2/20/201913901Windows: 158. 컴퓨터와 사용자의 SID(security identifier) 확인 방법
... 61  62  63  64  65  66  67  68  69  70  71  [72]  73  74  75  ...