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

비밀번호

댓글 작성자
 




... 76  77  78  79  80  81  82  83  84  85  86  87  [88]  89  90  ...
NoWriterDateCnt.TitleFile(s)
11460정성태3/13/201811594디버깅 기술: 112. windbg - 닷넷 메모리 덤프에서 전역 객체의 내용을 조사하는 방법
11459정성태3/13/201811335오류 유형: 453. Debug Diagnostic Tool에서 mscordacwks.dll을 찾지 못하는 문제
11458정성태2/21/201812860오류 유형: 452. This share requires the obsolete SMB1 protocol, which is unsafe and could expose your system to attack. [1]
11457정성태2/17/201817719.NET Framework: 732. C# - Task.ContinueWith 설명 [1]파일 다운로드1
11456정성태2/17/201822506.NET Framework: 731. C# - await을 Task 타입이 아닌 사용자 정의 타입에 적용하는 방법 [7]파일 다운로드1
11455정성태2/17/201812784오류 유형: 451. ASP.NET Core - An error occurred during the compilation of a resource required to process this request.
11454정성태2/12/201821121기타: 71. 만료된 Office 제품 키를 변경하는 방법
11453정성태1/31/201812656오류 유형: 450. Azure Cloud Services(classic) 배포 시 "Certificate with thumbprint ... doesn't exist." 오류 발생
11452정성태1/31/201818023기타: 70. 재현 가능한 최소한의 예제 프로젝트란? [3]파일 다운로드1
11451정성태1/24/201812882디버깅 기술: 111. x86 메모리 덤프 분석 시 닷넷 메서드의 호출 인자 값 확인
11450정성태1/24/201826489Windows: 146. PowerShell로 원격 프로세스(EXE, BAT) 실행하는 방법 [1]
11449정성태1/23/201815339오류 유형: 449. 단위 테스트 - Could not load file or assembly 'Microsoft.VisualStudio.QualityTools.VideoRecorderEngine' or one of its dependencies. [1]
11448정성태1/20/201812478오류 유형: 448. Fakes를 포함한 단위 테스트 프로젝트를 빌드 시 CS0619 관련 오류 발생
11447정성태1/20/201813980.NET Framework: 730. dotnet user-secrets 명령어 [2]파일 다운로드1
11446정성태1/20/201815341.NET Framework: 729. windbg로 살펴보는 GC heap의 Segment 구조 [2]파일 다운로드1
11445정성태1/20/201812700.NET Framework: 728. windbg - 눈으로 확인하는 Workstation GC / Server GC
11444정성태1/19/201813649VS.NET IDE: 125. Visual Studio에서 Selenium WebDriver를 이용한 웹 브라우저 단위 테스트 구성파일 다운로드1
11443정성태1/18/201813407VC++: 124. libuv 모듈 살펴 보기
11442정성태1/18/201811833개발 환경 구성: 353. ASP.NET Core 프로젝트의 "Enable unmanaged code debugging" 옵션 켜는 방법
11441정성태1/18/201811048오류 유형: 447. ASP.NET Core 배포 오류 - Ensure that restore has run and that you have included '...' in the TargetFrameworks for your project.
11440정성태1/17/201813614.NET Framework: 727. ASP.NET의 HttpContext.Current 구현에 대응하는 ASP.NET Core의 IHttpContextAccessor/HttpContextAccessor 사용법파일 다운로드1
11439정성태1/17/201817906기타: 69. C# - CPU 100% 부하 주는 프로그램파일 다운로드1
11438정성태1/17/201813142오류 유형: 446. Error CS0234 The type or namespace name 'ITuple' does not exist in the namespace
11437정성태1/17/201812360VS.NET IDE: 124. Platform Toolset 설정에 따른 Visual C++의 헤더 파일 기본 디렉터리
11436정성태1/16/201814067개발 환경 구성: 352. ASP.NET Core (EXE) 프로세스가 IIS에서 호스팅되는 방법 - ASP.NET Core Module(AspNetCoreModule) [4]
11435정성태1/16/201815033개발 환경 구성: 351. OWIN 웹 서버(EXE)를 IIS에서 호스팅하는 방법 - HttpPlatformHandler (Reverse Proxy)파일 다운로드2
... 76  77  78  79  80  81  82  83  84  85  86  87  [88]  89  90  ...