diff --git "a/zh_Hant-en_US.tsv" "b/zh_Hant-en_US.tsv" new file mode 100644--- /dev/null +++ "b/zh_Hant-en_US.tsv" @@ -0,0 +1,1681 @@ +source_string target_string license +色階檔的編修與呈現 Edit CPT and Colorbar CC-BY-4.0 +目標 Goal CC-BY-4.0 +直接觀看\\ `指令稿`_ Go to the final `Script`_ CC-BY-4.0 +使用的指令與概念 Commands and Techniques CC-BY-4.0 +``grdinfo`` - **查閱網格檔的基本資訊** ``grdinfo`` - **display basic information from a grid file** CC-BY-4.0 +``grdimage`` - **繪製著色影像** ``grdimage`` - **plot colored image** CC-BY-4.0 +前置作業 Tasks before plotting CC-BY-4.0 +操作流程 Procedure CC-BY-4.0 +$ 某GMT指令 --長指令名稱=長指令參數 ... # 和短指令一樣,可以無限增加 $ gmt command --long_command_name=long_coomand_value ... # Like short commands, we can add as many long commands as we like in a single line CC-BY-4.0 +指令稿 Script CC-BY-4.0 +本地圖的最終指令稿如下: The final script for our map is: CC-BY-4.0 +觀看\\ `最終版地圖`_ Check the `final map`_ CC-BY-4.0 +習題 Exercise CC-BY-4.0 +製作第一張地圖 Make Your First Map CC-BY-4.0 +本教學適用於 GMT 6 的現代模式。如須參閱 GMT 6 (傳統模式) 與 GMT 4-5 繪製相同地圖的教程,\\ `請至這裡 `_。 This instruction is for the Modern Mode in GMT 6. For making the same map using the GMT 6 Classic Mode or GMT 4-5, Please go to `this page `_. CC-BY-4.0 +說到 GMT 中最簡單的繪圖指令,那非 ``coast`` 莫屬。在本章中,我們要來解說如何用 ``coast`` 製作海岸線地圖、GMT 本身的參數輸入風格,以及如何調整這些參數。 The very first command you need to learn is definitely ``coast``, which is also the easiest command for mapping. In this chapter, we’re going to see how to make a map with coastlines using ``coast``. The other topics in this chapter are the style of GMT input and how to set up these input parameters. CC-BY-4.0 +製作一張\\ `群島海 `_ (Archipelago Sea) 的地圖,如下圖所示。群島海位於北歐,是波羅的海的一個附屬海,海如其名,被大小不等的眾多島嶼給佔據。事實上,群島海很有可能是擁有最多島嶼的海,雖然大部分的島都很小就是了。西邊的最大島嶼叫做奧蘭島 (Åland),屬於芬蘭下轄的自治區。這麼多島嶼的地方,用來觀察 ``coast`` 的各種調整效果再適合不過了。 Make a map of the `Archipelago Sea `_, as the figure here shows. Located in Northern Europe, the Archipelago Sea is part of the Baltic Sea. As its name suggests, the sea is occupied by numerous islands in any size. Although Most islands are small, the Archipelago Sea possibly contains the most island in the world. The largest island in the archipelago is Åland, an autonomous region of Finland. Such a place makes itself ideal for showing how ``coast`` can fine-tune your coastline map. CC-BY-4.0 +``coast`` - **繪製海岸線** ``coast`` - **plot shorelines** CC-BY-4.0 +GMT 共用選項:``-B`` ``-J`` ``-R`` ``-U`` GMT shared options: ``-B`` ``-J`` ``-R`` ``-U`` CC-BY-4.0 +GMT 的命令列參數調整 How to adjust parameters at a GMT command line CC-BY-4.0 +調整地圖邊框的簡單方法 A simple way to set up a map frame CC-BY-4.0 +使用 GMT 輸出不同格式的地圖 Using GMT to generate a map in different formats CC-BY-4.0 +繪製地圖的第一步,是決定我們繪製的地區。雖然我們已經知道要畫的是群島海了,但沒有詳細的經緯度是不行的。最方便取得經緯度的作法,就是去 `Google Map `_ 網站,搜尋 *Archipelago Sea*,然後視窗就會移到這片海域的附近。以右鍵在你想要當作地圖邊界的區域底點一下,選「\\ *這是哪裡?*\\ 」,底下就會出現點選區域的名稱和經緯度。 The first step of plotting a map is to determine the area of interest. Even though we know we are going to plot the Archipelago Sea, we still can’t start without a precise map extent. The most convenient way to retrieve map extent in Lat/Long representation is to go to `Google Maps `_ and search for Archipelago Sea. When the map jumps to the region of our interest, right-click on “What’s here?”. Then the name of the area and the Lat/Long would appear in the bottom. CC-BY-4.0 +注意一下經緯度的表示法,跳出來的視窗中有兩個數字,第一個 `59.865253` 是緯度,正值表示北緯,負值表示南緯。而第二個 `19.435697` 是經度,正值表示東經,負值表示西經。另外,這裡也不採用「度分秒」的角度格式,而是把所有零頭都歸到「度」後的小數點。這種格式比較容易進行數學運算,所以也是 GMT 預設採用的座標標示法。 Note how longitude and latitude are represented here: there are two numbers in the pop-up window. The first one `59.865253` is latitude; positive and negative values are N and S, respectively. The second one `19.435697` is longitude; positive and negative values are E and W, respectively. Also, it does not use the “degrees, minutes, seconds” convention; instead, it converts all minutes and seconds and gives you a real number in degrees. It’s much easier to use this format in math calculation, and thus GMT adopts it as the default representation for geographical coordinates. CC-BY-4.0 +查看一番後,這裡我們選擇經度從 19.42 到 22.95,緯度從 59.71 到 60.56 的這塊區域來畫圖。你也可以自由選擇你喜歡的區域。接著打開\\ :ref:`終端機`,輸入如下指令: After taking a look, we are going to select longitude from 19.42 to 22.95 degrees and latitude from 59.71 to 60.56 degrees for mapping. Also, feel free to try whatever region if you would like! Now, open :ref:`Terminal` and enter the following prompt: CC-BY-4.0 +會看到一連串的說明,``coast`` 的全部語法和選項都會列在上面。如果你對選項的意思很熟,只是要確認一下的話,你也可以改成這樣輸入,如此一來,就只有選項用法的部份會顯示在螢幕上。 You would see a few pages that show all the syntax and options of ``coast``. If you’ve already been super familiar with these options and want to make sure for the usage, you can also enter the command like the following line, and it will only show the syntax on screen. CC-BY-4.0 +幾乎所有 GMT 的指令,包含 ``coast``,都是以類似如下的語法操作: Almost all GMT commands, including ``coast``, have a syntax like this: CC-BY-4.0 +$ gmt 指令 (輸入檔) [選項1 選項2 選項3...] $ gmt command (input_file) [option1 option2 option3...] CC-BY-4.0 +所有以負號 (-) 開頭的文字,程式都會解讀成選項,而不是負號開頭的東西,就會是輸入檔。通常每個指令都會有一兩個必填的選項,而其他的選項如果沒指定的話,就會使用預設值。輸入檔和選項的先後次序,對 GMT 而言是沒差的,你也可以打完所有選項後,再打上輸入檔的名字。 Every string starting with a minus sign (-) is an **option**, or more technically speaking, a **flag** or an **argument**. If a string doesn’t start with a minus sign, it could only be the input file(s). Every GMT command usually has a required option or two; if other options are omitted, GMT will use the default settings. The order between options and input files doesn’t matter at all. For example, it is ok to place all options before the input file name. CC-BY-4.0 +不過 ``coast`` 這個指令稍微特別一點點,它\\ **不用給定輸入檔**\\ !這樣程式要怎麼知道海岸線位在哪呢?原來,GMT 的標準安裝內,已經有附上一個稱為 `GSHHG `_ 的資料庫,這個資料庫內含有許多世界的基本資料,像是海岸線、國界、河流等等的位置,而 ``coast`` 做的事情,就是從這個資料庫裡面讀取資料,畫到地圖上。因此精確說來, ``coast`` 不僅能畫海岸線,也可以畫河流、國界等等的特徵。不用給定輸入檔,我們只要專心在設定參數上就行了!第一個參數當然就是地圖的座標,是透過 ``-R`` (Region) 選項來設定的,選項值直接打在 ``-R`` 後方,不需要空格隔開。一般來說,``-R`` 選項有兩種給定方法: ``coast`` has got a little special: **an input file is not required**! Given that, how does the program know where the coastline is? The answer is simple: there is a database called `GSHHG `_ along with the standard installation of GMT. The database contains a lot of necessary information about the world, like coastline, country borders, rivers, etc. What ``coast`` does is to load data from GSHHS and plot them on your map. Thus, ``coast`` is not only capable of drawing coastline but is also used for drawing water bodies and countries. When using ``coast``, we only need to focus on setting up options! The first required flag is ``-R`` (Region), which is used to specify extent (covered area) of a map. We can just put all the parameters directly after ``-R``, without any spaces. Typically, there are two ways to specify extent using ``-R`` flag: CC-BY-4.0 +第一種格式為 ``西邊界/東邊界/南邊界/北邊界``,也就是由 x 座標 (經度) 和 y 座標 (緯度) 的範圍來指定。第二種格式使用時,要在最後面加上 ``r``,這樣子四個欄位就會是 ``左下角經度/左下角緯度/右上角經度/右上角緯度``。以上兩行實際執行時,效果會一模一樣。在本章中,我們會使用第一種格式繪圖。 The first format is ``W_Border/E_Border/S_Border/N_Border``; that is, we specify the region by x coordinate (longitude) and y coordinate (latitude). The second format needs the coordinates of the bottom-left (BL) corner and the top-right (TR) corner, so it becomes ``BL_long/BL_lat/TR_long/TR_lat``. Don’t forget to add an ``r`` if you are using the second way. No matter whichever method you use, it would give you the same result. Here we will use the first format in this chapter. CC-BY-4.0 +對於簡單的地圖來說,一個 GMT 指令就能完成所有步驟。以本章的地圖爲例,我們只需產生海岸線、陸海域填色、地圖格線、標題等的簡單元素,這些東西靠 ``coast`` 一個指令就能做到。因此除了 ``-R`` 以外,我們還要給定另一個參數來指定輸出檔名稱。這個參數就是輸出檔的副檔名。語法如下: For a simple map, a single GMT command can get the job done. For example, in this chapter we only need basic elements like coastline, color filling, map grids, and a title. ``coast`` is capable of doing all of that. Thus, after adding ``-R`` we still need another flag to specify the output file name. This flag is actually the file extension (format). The syntax goes like this: CC-BY-4.0 +"'-png archi_sea # archi_sea 是輸出檔檔名。注意 png 和檔名之間有空格。輸出檔的全名爲 archi_sea.png +-pdf archi_sea # PDF 格式輸出。檔名爲 archi_sea.pdf。'" "'-png archi_sea # archi_sea is the name of the output file. Note that there is a space between png and the filename. The full file name is archi_sea.png +-pdf archi_sea # generate PDF format instead. The file name is archi_sea.pdf.'" CC-BY-4.0 +其他可選的格式還有 ``-eps``, ``-ps``, ``-jpg`` 等等,可參閱官方手冊的\\ `格式列表 `_。現在我們就來看看把 ``-R`` 和 ``-png`` 選項拼在一起會發生什麼事。在命令行輸入以下指令然後執行看看: The other available formats include ``-eps``, ``-ps``, ``-jpg``, and so on, according to the `table of formats `_ in the GMT official manual. Now let see how it goes after combining ``-R`` and ``-png``. Enter the following prompt in the terminal and run it: CC-BY-4.0 +嗚唔,出現錯誤了!問題出在我們還有一些選項沒有給定。這是有關「繪圖樣式」的設定。GMT 要求我們至少給定一種繪圖樣式,我們先使用 ``-W`` 以指定海岸線的畫筆屬性。畫筆具有三種屬性:粗細、顏色跟樣式,給定的語法是 Oops, an error jumps out! The issue here is that the command still lacks a few options about the “drawing style.” GMT asks us to specify at least one drawing style. Here we can use ``-W`` for the coastline pen attribute. A pen attribute contains three values: thickness, color, and style. The syntax is CC-BY-4.0 +'-W粗細,顏色,樣式' '-Wlinewidth,linecolor,linestyle' CC-BY-4.0 +如果省略時,就使用預設的樣式作圖。我們試著指定指定畫筆粗細為 0.1 點 (1 點 = 1/72 英吋 = 0.03527 公分) 的黑色線條看看: If any is omitted, the default is used. Here we try to specify a black pen with a thickness at 0.1 points (1 point = 1/72 inches = 0.03527 cm): CC-BY-4.0 +``0.1p`` 代表的就是 0.1 點,``black`` 就是黑色,顯而易見的我們沒有指定線條樣式,程式就會以預設的實心線條作圖。值得一提的還有,我們在這裡使用了 GMT 預先定義的顏色名字,這些名字可以在`這裡 `_\\ 查詢。 ``0.1p``means 0.1 points, and ``black`` tells GMT to use a black pen. We didn’t specify line style here so that GMT will use a solid line. Note that here we used the pre-defined color name in GMT, and all of these names are listed `here `_. CC-BY-4.0 +有關畫筆的進階樣式設定,例如設定線條樣式、利用 RGB 值自訂顏色等,會在「\\ :doc:`pen_and_painting`\\ 」詳加描述。 For the advanced and detailed settings of the pen attributes, like line styles or custom colors using RGB values, please go to :doc:`pen_and_painting`. CC-BY-4.0 +目前已經設定了三個選項,``coast`` 已經可以正常執行了。把所有的選項合併在一起輸入後,你應該就能得到輸出圖檔 ``archi_sea.png``: Now we have set 3 arguments up and ``coast`` should be able to run smoothly. Type the following command, and if you see this: CC-BY-4.0 +這張地圖基本上已經描繪出群島海的海岸線,但由於缺乏了顏色和經緯度座標等等資訊,使地圖資訊難以判讀。另外,因爲 GMT 預設的地圖座標是 WGS 84 經緯度,所以高緯度地區的地圖都會被拉得很扁平。我們可以換一個投影座標,讓海岸線沿緯度的變化能清楚地顯示。GMT 中以 ``-J`` 設定投影法,有五花八門的樣式可供選擇,這裡我們來選個在畫小範圍地圖時很常用的\\ `麥卡托投影法 `_\\ 來看看。語法是: The very first map has already shown the coastline of the Archipelago Sea, but it is hard to read the map because we didn't plot colors and Lat/Long information. Besides, the default map coordinates in GMT is WGS 84, which makes your map look flattened if it is in the high-latitude region. We can change projected coordinates so that it is clear to see the coastline along the latitude. In GMT, the ``-J`` flag is used to assign a map projection. There are various projections at your service, but here we are going to pick a common one for drawing a regional map: `Mercator projection `_. The syntax is: CC-BY-4.0 +在 ``-J`` 後面的 ``M`` 為麥卡托投影的代號,``6i`` 代表地圖橫向的寬度為 6 英吋 (inch)。如果你對英吋有多長不熟,也可以換成 ``-JM15c``,代表地圖橫向的寬度為 15 公分 (cm),差不多就是 6 吋的長度。 The ``M`` after the ``-J`` is the code of Mercator projection, and ``6i`` means that the width of the map is 6 inches. If you don’t know how long 6 inches are, just change it into ``-JM15c``. This means the width of the map is 15 centimeters, which is roughly 6 inches wide. CC-BY-4.0 +``-J`` 和 ``-R`` 具有連動關係,也就是說在不同投影法之下,給定地圖邊界和尺寸的方法與參數輸入模式會有點不同,請參閱 `GMT 官方說明 `_。有關於各種投影法的適用情形,請參閱地理資訊系統與測地學專書的介紹。另外,GMT 預設的大地座標系統是 `WGS84 `_ 參考橢球,如欲調整此設定,請參閱\\ :doc:`layout_design`。 ``-J`` and ``-R`` are related to each other. When the map projection changes, the way to set map extent and size also changes a little bit. Please see `GMT official documentation `_ for more details. For the usage of different map projections, please see any GIS or geodesy textbooks. In addition, the default geodetic datum of GMT is the WGS84 reference ellipsoid. If you would like to change it, please see :doc:`layout_design`. CC-BY-4.0 +另外爲了讓地圖易於判讀,我們也可以為陸地和海洋加上顏色,使用的分別是 ``-G`` (Ground) 和 ``-S`` (Sea) 選項: To improve the readability of the map, we can fill land and sea areas with colors. We will need ``-G`` (Ground) and ``-S`` (Sea) flags respectively: CC-BY-4.0 +``darkseagreen2`` 和 ``cornflowerblue`` 都跟 ``black`` 一樣,是 GMT 預先設定的顏色名字。把以上的選項全部都拼在一起,大概就像這樣: Like ``black``, ``darkseagreen2`` and ``cornflowerblue`` are also pre-defined color names in GMT. Let's pull all options together, and you will get the following command: CC-BY-4.0 +可以看得出來現在指令已經有點長了,這是 GMT 的常態,尤其會在你嘗試調整預設值、畫出更漂亮的地圖時發生。在命令列操作時,這不是什麼大問題,終端機都會自動幫你換行,不過之後如果有要寫 GMT 腳本的需求,為了排版美觀,可以使用 UNIX 常見的接續符號 ``\\``,換行繼續輸入指令。以下指令跟上面的指令效果一模一樣: Now the command gets a bit longer, which is quite normal when using GMT, especially when you want to change the defaults and make a pretty map. It’s not a problem when a long command is entered at the prompt line because the terminal window would automatically go to the next line. However, if later you are writing a GMT script and want to make your script neat, you can use the UNIX line-break sign ``\\`` to continue the command at a new line. The following example would give the same result as the previous one: CC-BY-4.0 +本文為了方便閱讀起見,也會使用 ``\\`` 分隔過長的段落,但如果你想要在一行之內完成此道指令,則可以省略這個符號。 In this tutorial, we also use ``\\`` to break a long command for clarity. If you would like to finish your command in one line, just ignore this line-break sign. CC-BY-4.0 +在 GMT 6 中,預設的海岸線是以最高等級的解析度呈現。如果你的地圖涵蓋很大的區域,海岸線可能會太過密集,模糊了地圖的焦點。要解決此問題,可以更改海岸線解析度的選項 ``-D``,接受的設定值有 ``f`` (full,完整)、``h`` (high,高)、``i`` (intermediate,中)、``l`` (low,低) 和 ``c`` (crude,粗糙)。例如中等解析度的設定值就是 ``-Di``。 In GMT 6, the coastline is plotted with the highest resolution. If your map covers a broad region, this will cause some problems as coastlines are too dense. To solve this issue, we can change the resolution of coastlines by setting the ``-D`` option. The accepted parameters are ``f`` (full), ``h`` (high), ``i`` (intermediate), ``l`` (low), and ``c`` (crude). For example, ``-Di`` sets the intermediate resolution to the coastline. CC-BY-4.0 +以上指令畫出來的地圖如下所示 The above command generates a map like this CC-BY-4.0 +由此可見,光是調整投影法,以及陸地與海洋的顏色,整張圖就會與脫胎換骨。 Here we can see that the map totally changed by only adjusting the map projection and the colors of land and sea. CC-BY-4.0 +目前主圖大致上都完成,剩下邊框需要加入。GMT 使用 ``-B`` 選項設定地圖的邊框與附屬要件,如格線、座標標誌、底色、標題等等,合起來稱為底圖 (Basemap) 設定。``-B`` 選項是 GMT 中最複雜的選項之一,有著五花八門的樣式組合可供選擇。這邊我們先講最簡單的兩種組合 Now the main map is almost finished, and it’s time to add a map frame. GMT uses ``-B`` to tweak map frame and associated elements, like grids, ticks, annotations, and title. They are collectively called the Basemap settings. ``-B`` is one of the most complex arguments in GMT since it’s got tons of styles for your choice. Here we are going to introduce two simplest combinations: CC-BY-4.0 +"'-Ba座標數值間隔f座標刻度間隔g格線間隔 +-B地圖四邊設定+t標題'" "'-Ba(annotation_spacing)f(tick_spacing)g(grid_spacing) +-B(four_borders)+t(title)'" CC-BY-4.0 +第一種組合可以給定地圖邊框的數值、刻度與格線設定,而且使用與 ``-R`` 相同的座標單位,例如 ``-Ba1f1g1`` 代表數值、刻度與格線都是每隔 1 度畫一條,而 ``-Ba2f1`` 是「每隔 2 度標示座標、每隔 1 度標示刻度,然後不加格線」。第二種組合可以調整地圖的四邊配置,使用 W、S、E、N 來表示東、南、西、北,大寫表示加上邊框也加上數值,小寫表示只加上邊框而不加數值,如果不加就是不畫邊框。例如 ``-Bwsne`` 就是單純畫上邊框,不加上數值顯示 (前面的 a 設定會無效),而 ``-BWSe`` 則代表「在西方與南方畫邊框且標上數值、在東方單純畫邊框、在北方什麼都不做 (地圖上端會破一個洞)」。第二種組合可以透過 ``+t`` 來延伸,後方可以輸入此幅地圖的標題。兩種組合可以同時加在一個指令內,例如說我們的地圖如果這樣設計: The first combination gives the spacing number to annotation (tick mark), tick, and grid. It used the same unit as specified in ``-R``. For example, ``-Ba1f1g1`` means annotations, ticks, and grids are plotted at every degree; ``-Ba2f1`` means that “annotation is labeled every other degree, tick is plotted every degree, and don’t add any grid.” The second combination is for four sides of a map, and it uses W, S, E, N for West, South, East, and North. If it’s a capital letter, GMT puts everything (frame and annotations) at this side; if it’s a lowercase letter, only the frame will be added to this side; if you don’t add a letter, nothing will be plotted. For example, ``-Bwsne`` is to put a map frame without any annotation (ignoring the ``-Ba`` setting in the first combination). ``-BWSe`` is to put a frame with annotation at the west and south sides, but only frame itself at east side (and no frame at the north -- the map would look broken!). It’s also ok to add ``+t`` at the second combination, which a map title followed by the ``+t`` flag. Two combinations can be both used in the same command. For instance, we can design our map like this: CC-BY-4.0 +那麼,地圖四邊都會加上邊框,但只有西側和南側會標上經緯度,經緯度會以每 2 度標示一次,刻度 (黑白線區間) 以每 0.5 度標示一次,格線每 1 度就有一條,而且還會加上 *Archipelago Sea* 這個標題。畫出來的樣子如下所示: In this case, a map frame is added to all four edges, but annotations are only marked at the west side and the south side. Lat/long annotations are at every 2 degrees, ticks (the black and white bars in the map frame) are 0.5 degrees wide, and grid lines are drawn at every degree. The map is also entitled as *Archipelago Sea*, like the following figure shows: CC-BY-4.0 +事實上,``-B`` 選項其實是另一個稱為 ``basemap`` 指令的精簡版。許多更複雜的邊框設定可以透過 ``basemap`` 來達成,如此一來,程式會先畫好邊框,我們再把其他圖層填到邊框內即可。有關進階的 ``-B`` 選項調整,像是自訂數值標記、各軸分開設定、主格線與次要格線、中文字標題與標記等等,會在\\ **之後的章節**\\ 說明。 In fact, ``-B`` is a shortened version of another GMT command called ``basemap``. We can use ``basemap`` to plot many more complex frame settings independently, and then filling the map content into the frame is just simple. For advanced ``-B`` options like custom tick marks, adjusting single axis, primary and secondary grid, and special characters, please see **later chapter**. CC-BY-4.0 +你會發現,群島海的島實在太多,如果我們還想在上面標上其他資訊的話,這些群島很容易讓看地圖的人分心。為了精簡地圖,讓讀者聚焦在關鍵資訊上,``coast`` 提供了 ``-A`` 選項,這個選項可以讓我們輸入島嶼面積 (單位是平方公里),然後 ``coast`` 會省略比這個面積還小的島嶼不畫。這裡我們要省略比 0.1 平方公里還小的島嶼: You would probably feel that there are too many islands in the Archipelago Sea, and they easily distract readers, especially if we want to label other information on the map. To simplify our map and make readers focus on crucial details, ``coast`` provides ``-A`` flag to let us specify a minimum area of an island, in square kilometers. Once it’s set, ``coast`` would ignore any island that is smaller than the given area. Here we are going to make islands that are lower than 0.1 square kilometers disappear: CC-BY-4.0 +島嶼比較少,看起來清爽多了,卻又不會喪失「群島海」名稱的霸氣。 "With fewer islands, the map looks cleaner but still keeps the sense of its name, the ""Archipelago Sea.""" CC-BY-4.0 +我們的地圖目前已大致完成。最後,可以再使用 ``-U`` 選項在左下角加上 GMT 軟體的標誌。``-U`` 選項可以直接加在指令內,不用給定任何值。 Now our map is close to finish. Lastly, let us use the ``-U`` flag to add a GMT mark and time stamp at the bottom left corner. ``-U`` flag can go along without any additional parameters. CC-BY-4.0 +「繪製海岸線圖 - 以 **19.42E - 22.95E,59.71N - 60.56N** 為邊界,麥卡托投影,地圖橫向寬 **6** 吋,海岸線的線條使用 **0.1** 點的黑色線,陸地使用 ``darkseagreen2`` 填色,海洋使用 ``cornflowerblue`` 填色,四邊繪製邊框並在左側和下側標上刻度數值,數值間隔 **2** 度,刻度間隔 **0.5** 度,格線間隔 **1** 度,標題為 *Archipelago Sea*,存檔為 ``archi_sea.png``。」 “Plot the coastline map - map extent is set to **(19.42E - 22.95E, 59.71N - 60.56N)** in Mercator projection and **6** inches wide. Coastlines are black and **0.1** point wide. The land area is filled with the color ``darkseagreen2``, and the water area is filled with ``cornflowerblue``. We plot a border frame at all of its edges and put annotation marks on the left and bottom. Annotation spacing is **2** degrees, tick spacing is **0.5** degrees, and grid spacing is **1** degree. The map is entitled *Archipelago Sea* and saved as ``archi_sea.png``.” CC-BY-4.0 +PyGMT 指令稿 PyGMT script CC-BY-4.0 +使用 PyGMT,可以如下腳本繪製本地圖: You can make the same map using the following PyGMT script: CC-BY-4.0 +你可以使用以下的 Binder 連結嘗試此程式碼: You can use the following Binder link to try this code: CC-BY-4.0 +畫出蘇拉威西島 (*Sulawesi*) 的海岸線圖。蘇拉威西島是印尼第四大島,外觀非常有趣,\\ 像是字母 K 或是正在跳舞的人。座標可使用 ``118.34E 至 125.70E``,以及 ``6.12S 至 2.08N``。 Make a map illustrating the coastline of *Sulawesi*. Sulawesi is the fourth largest island in Indonesia with a fun shape like the letter K or a dancing person. Use the coordinate ``118.34E to 125.70E`` and ``6.12S to 2.08N``. CC-BY-4.0 +等高線地圖及地形剖面 Contours and Profiles CC-BY-4.0 +在本章中,我們要使用 GMT 繪製等高線圖與地形剖面圖,這兩種地圖非常適合用來表示地形的\\ 升降起伏,以及不同地點的陡峭程度。如果你是個登山客,想必它們會是你最愛用的地圖類型。 This chapter will use GMT to plot contour lines and a topographic profile. Both kinds are suitable for representing topography and whether there is rugged terrain or not. They are beautiful tools for hikers and mountain goers. CC-BY-4.0 +從鄰近區域觀看的馬榮火山,完美的外型令人震懾。Tomas Tam 的攝影作品。 Mayon Volcano from a nearby region with a stunning shape. Photo by Tomas Tam. CC-BY-4.0 +``grdimage`` - 繪製暈渲圖 ``grdimage`` - draw hillshade CC-BY-4.0 +``pstext`` - 在地圖上加入文字 ``pstext`` - add text on the map CC-BY-4.0 +版面設計與地圖的幾何布局 Design Map Layout CC-BY-4.0 +本教學適用於 GMT 6 的現代模式。如須參閱 GMT 6 (傳統模式) 與 GMT 4-5 繪製相似地圖的教程,\\ `請至這裡 `_。 This instruction is for the Modern Mode in GMT 6. For making the same map using the GMT 6 Classic Mode or GMT 4-5, `Please go to this page `_ (only final script available). CC-BY-4.0 +接下來讓我們來探討一下 GMT 的版面設計功能。GMT 使用了許多預設選項,讓使用者不需做太多設定就能產生想要的地圖。如果我們想設計比較複雜的配置,例如版面分割、邊框樣式調整、字型與字體樣式,就需要調整 GMT 的「使用者組態設定」。另外,我們也會在這裡介紹地理空間資料常用的兩大類座標:平面與球面,以及 GMT 作圖時的相關設定。 "Now let us see how GMT deals with the map layout. GMT uses many pre-defined option values so that uses don't need to set a lot of things up for making a map. However, if we want to have a more complex design such as multiple panels, different frame types, and tweaking font style, we have to adjust GMT's ""user configuration."" Also, in this chapter we will introduce the two major projection types used for geospatial data: cylindrical (Mercator) and planar (Lambert) and the associated settings in GMT." CC-BY-4.0 +繪製從蒙古\\ *烏蘭巴托* (Ulaanbaatar) 到美國\\ *西雅圖* (Seattle) 的\\ `大圓路徑 `_ (**Great Circle** Route) 與\\ `恆向線 `_ (**Rhumb Line**)。大圓路徑指的是沿著大圓 (半徑為地球半徑的的圓) 前進的路徑,恆向線則是對於所有的子午線,交角皆相等的路線。本章地圖使用了兩個不同的投影方法,上圖為「蘭伯特等積方位投影」 (**Lambert** azimuthal equal-area projection) ,下圖為「麥卡托投影」(**Mercator** Projection)。圖中說明了幾個特點: Draw the `Great Circle Route `_ and the `Rhumb Line `_ between *Ulaanbaatar*, Mongolia, and *Seattle*, USA. A great circle route is the path along the great circle (the circle whose radius equals the radius of Earth), and a rhumb line is a path whose incident angle to any meridian is the same. The map of this chapter uses two different projections. The upper panel uses the **Lambert** azimuthal equal-area projection, and the lower panel uses the **Mercator** Projection. The map shows some interesting points: CC-BY-4.0 +恆向線在麥卡托投影中會以直線呈現,而大圓路徑在相同的圖中則是曲線。不過,大圓路徑才是兩地之間實際較短的路徑。 A rhumb line is a straight line when the map is drawing using the Mercator projection, while the great circle route is a curved line on the same map. However, the great circle route is actually the shortest path between any two locations. CC-BY-4.0 +連接到蘭伯特等積方位投影中心點 (本例中為烏蘭巴托) 的大圓路徑會是直線,恆向線則變成曲線。這是比較能直觀連結它們的實際長度的一種方法,也是投影名稱的「方位」二字緣由 (大圓路徑保持在相同方位)。 The great circle route connecting any point to the center of the Lambert map (Ulaanbaatar in this example) is a straight line. On the other hand, the thumb line becomes a curved line in this case. You can see that a Lambert map does a better job of keeping the relative length of different paths, as well as their actual direction (which is why this projection is referred to as an azimuthal projection). CC-BY-4.0 +另外,本地圖也替換了 GMT 的預設字型、顏色與版面配置。這些細節將會在以下部份一一解說。 We will also change the GMT default settings including fonts, colors, and layout for this map. You will find more details in this chapter. CC-BY-4.0 +``defaults`` - **查看 GMT 的預設作圖參數** ``defaults`` - **check GMT's default map parameters** CC-BY-4.0 +``set`` - **更改 GMT 的預設作圖參數** ``set`` - **change GMT's default map parameters** CC-BY-4.0 +``plot`` - **在地理座標系統上畫點和線** ``plot`` - **plot points and lines using under a geographical coordinate system** CC-BY-4.0 +``text`` - **詳細的設定標記在圖上的文字** ``text`` - **set text in detail on a map** CC-BY-4.0 +``basemap`` - 設定繪圖區、座標軸與邊框 ``basemap`` - set up mapping area, axes, and map frame CC-BY-4.0 +``coast`` - 繪製海岸線與國界 ``coast`` - plot shorelines and borders CC-BY-4.0 +外部指令 ``rm`` - **刪除檔案** (Windows 為 ``del``) External command ``rm`` - **delete a file** (``del`` for Windows) CC-BY-4.0 +外部指令 ``echo`` - 把資料輸入到管線命令中 External command ``echo`` - pass input data through a pipe CC-BY-4.0 +GMT 共用選項:``-X`` ``-Y`` ``-:`` GMT shared options: ``-X`` ``-Y`` ``-:`` CC-BY-4.0 +GMT 的預設參數與 ``gmt.conf`` 檔案 GMT default settings and the ``gmt.conf`` file CC-BY-4.0 +地理座標的給定方式 More ways to specify geographical coordinates CC-BY-4.0 +地圖版面的設定 How to set up a map layout CC-BY-4.0 +文字風格設定 How to change font style CC-BY-4.0 +GMT 針對不同投影座標系統的不同處理方式 How GMT makes a map using a different projection system CC-BY-4.0 +我們要先取得烏蘭巴托與西雅圖兩地的經緯度座標。從 *Wikipedia* 的條目頁面中,可以找到「經緯度」的資訊欄位,點選連結後,可以看到不同座標系統的位置資訊,如下所示 (以烏蘭巴托為例)。 First, we have to get the coordinates for Ulaanbaatar and Seattle. On their *Wikipedia* page we can find the latitude and longitude of both cities, which is a link to more information about coordinates under different projection systems. Here we have an example of Ulaanbaatar. CC-BY-4.0 +注意在「\\ **WGS84**\\ 」欄位中,有兩種座標的格式。你要使用哪種都可以,GMT 都有支援。另外也請注意這裡的座標是「緯度在前,經度在後」。在下表中,也蒐集了兩地的經緯座標 (十進位制四捨五入至小數點第二位): "Note that there are two formats of coordinates in the **WGS84** field. Either of them works in this example as GMT supports both formats. The other thing worth paying attention to is the coordinates are represented by ""latitude-longitude"". We have collected the coordinates of both places in the following table (rounded to the second decimal place):" CC-BY-4.0 +城市 City CC-BY-4.0 +烏蘭巴托 Ulaanbaatar CC-BY-4.0 +西雅圖 Seattle CC-BY-4.0 +經緯度 (度分秒) Latitude/Longitude (Deg, Min, Sec) CC-BY-4.0 +經緯度 (十進位) Latitude/Longitude (Decimal) CC-BY-4.0 +為了方便使用這些資料,我們可以建立一個純文字文件 ``coord.txt``,再把兩地的座標資訊複製到文件中存檔,如此一來供 GMT 使用的資料表就建立完成。以下是使用十進位制座標的 ``coord.txt`` 內容: We can create a text file ``coord.txt`` and save the coordinate information to the file to easily access them later with GMT. Here's the content of ``coord.txt`` with the decimal formatted coordinates: CC-BY-4.0 +再次強調,資料中的第一欄現在是緯度 (y 值),第二欄是經度 (x 值)。這與我們在「\\ :doc:`scatter_plot`\\ 」一章中所使用的 xy 順序相反,不過只要適當的指定欄位意義,GMT 仍然可以讀取。另外,兩個欄位中間使用了「逗號」分隔,在 GMT 中也是可以接受的。 Let me emphasize that the first column is latitude (y) and the second column is longitude (x). This is opposite to the x-y order we used in the chapter :doc:`scatter_plot`. However, you'll see there is a way to specify the meaning of each column so that GMT can still recognize them correctly. In addition, we use commas to separate the columns here, which is acceptable for GMT too. CC-BY-4.0 +以下是使用度分秒制座標的 ``coord.txt`` 內容: Here's the content of ``coord.txt`` with the d/m/s coordinates: CC-BY-4.0 +注意我把所有的度分秒符號都統一成「冒號」,而且座標字串中間的空白都被移除了。這種格式是 GMT 接受的標準地理座標 (度分秒) 格式,如果你有一串地理座標資料是以度分秒格式儲存,記得在輸入 GMT 之前,把所有的度分秒符號都改為冒號,如上所示。 Note that I have changed all the degree, minute, and second symbols to colons and removed the space between the numbers. This is one of the standard longitude and latitude formats for GMT. If your geographical coordinates adopt this format, remember to check whether all the special symbols have been converted into colons before feeding it to GMT, as this example shows. CC-BY-4.0 +你也可以從這裡下載資料檔:\\ :download:`coord.txt `\\,這個版本使用度分秒制座標。 You can also download the data from here: :download:`coord.txt `. This file uses degrees, minutes, and seconds coordinates. CC-BY-4.0 +簡單小結 GMT 對於文字輸入檔與地理座標格式的要求: To summarize the requirements of data files and longitude and latitude format for GMT: CC-BY-4.0 +欄位的分隔符號可以是\\ **空白**\\ 、\\ **逗號** (``.csv`` 檔) 與 **Tab** (``.tsv`` 檔) 三者之一,但不能在同一個檔案中使用超過一種的分隔符號來分隔欄位。欄位代表的意義預設是第一欄 x 值、第二欄 y 值,不過可以在下指令時逐一指定。 The acceptable delimiters for separating columns include **space**, **comma** (as in ``.csv`` files), and **Tab** (as in ``.tsv`` files). However, you cannot use more than one kind of delimiter in a single file. By default, the first column is set to be the x value, and the second column is set to be the y value. You can override this setting when reading them using a GMT command. CC-BY-4.0 +地理座標可以採用\\ **十進位**\\ 或\\ **度分秒**: The acceptable formats for geographical coordinates are **decimal** and **degrees, minutes, and seconds**: CC-BY-4.0 +以十進位系統表示時,南緯要表示為負緯度,西經則表示為負經度或是東經 180 度之後持續累加,如經度 243 和 -63 都代表西經 63 度。 For the decimal system, a negative latitude represents the southern hemisphere, and a negative longitude or a longitude over 180 degrees represents the western hemisphere. For example, both 243 and -63 are 63 degrees W. CC-BY-4.0 +以度分秒系統表示時,使用 ``ddd:mm:ssF`` 的方法,``ddd`` 為度,``mm`` 為分,``ss`` 為秒,``F`` 則是 NEWS 四個字母之一。 For the degrees, minutes, and seconds system, the format is ``ddd:mm:ssF`` where ``ddd`` are degrees, ``mm`` are minutes, ``ss`` are seconds, and ``F`` is a letter noting N, E, W, or S. CC-BY-4.0 +讓我們從目標地圖的下半部 (麥卡托投影的部份) 開始吧。先來畫出海岸線與國界: Let's start from the lower part of the target map (the one using the Mercator projection). First of all, we draw the coastlines and country borders: CC-BY-4.0 +"land_color=""#CEB9A0"" # 陸域填色 + +gmt begin ulaanbaatar_seattle png + gmt basemap -R70/270/30S/70N -JM13c -B+tMercator + gmt coast -Dl -A1000 -G$land_color -N1/thick,60 -Ba40f20g20 + # -D: 調整海岸線解析度。因為我們畫的是全球資料,用不著高解析度的海岸線,所以設定為 l (low) 即可。 +gmt end" "land_color=""#CEB9A0"" # Color for land area + +gmt begin ulaanbaatar_seattle png + gmt basemap -R70/270/30S/70N -JM13c -B+tMercator + gmt coast -Dl -A1000 -G$land_color -N1/thick,60 -Ba40f20g20 + # -D: Adjust the coastline resolution. We set it to l (low) because we are drawing the global coastlines and do not need high-resolution data. +gmt end" CC-BY-4.0 +這張地圖的細節設定,例如字體大小、格線粗細等等,採用的是 GMT 的預設參數。你可以使用 ``defaults`` 指令在終端機中查看所有的參數值: For detailed settings of the map such as font size and gridline width, we use the default GMT parameters. You can use ``defaults`` to take a look at these values on the terminal: CC-BY-4.0 +螢幕的輸出如下所示: And this is what you would see on the screen: CC-BY-4.0 +"# +# GMT 6.0.0 Defaults file +# +# COLOR Parameters +# +COLOR_BACKGROUND = black +COLOR_FOREGROUND = white +COLOR_NAN = 127.5 +COLOR_MODEL = none +... #(以下省略)" "# +# GMT 6.0.0 Defaults file +# +# COLOR Parameters +# +COLOR_BACKGROUND = black +COLOR_FOREGROUND = white +COLOR_NAN = 127.5 +COLOR_MODEL = none +... #(skipped)" CC-BY-4.0 +所有不以 ``#`` 號開頭的每一行都是一個 GMT 參數,參數的名稱就是在這裡出現的大寫字串。所有參數的意思,都可以在 `GMT 的官方手冊 `_\\ 中找到。我們可以使用兩種方式更改預設的參數: A line that does not start with the ``#`` symbol represents a GMT parameter. The name of the parameter is that capitalized string. The meaning of each parameter can be found at the `official GMT manual `_. We have two ways to modify the default parameter settings: CC-BY-4.0 +在下 GMT 指令時,使用 ``--參數=設定值`` (\\ **長指令**\\ 語法)。在「\\ :doc:`cpt_colormap`\\ 」中,我們就是使用此方法調整 ``COLOR_NAN`` 的設定,讓地圖無資料的區域顯示為灰色。**使用此方法改變的參數只對這個指令有效**,其他指令仍然會使用原先的預設值。 When entering a GMT command, you can use ``--parameter=value`` (**long option** syntax). In :doc:`cpt_colormap`, we used this method to adjust the ``COLOR_NAN`` settings and make the no-data area rendered grey on the map. **The change by this way only applies to this GMT command** For the other commands, the default parameter values are still used. CC-BY-4.0 +使用 ``set`` 指令設定參數的預設值。它的語法如下: Use the ``set`` command to change the parameter value. it has the following syntax: CC-BY-4.0 +"$ gmt set 參數名1 參數值1 [參數名2 參數值2 參數名3 參數值3...] +# ---- 或是 ---- +$ gmt set 參數名1=參數值1 [參數名2=參數值2 參數名3=參數值3...]" "$ gmt set name1 value1 [name2 value2 name3 value3...] +# ---- or ---- +$ gmt set name1=value1 [name2=value2 name3=value3...]" CC-BY-4.0 +在本教學中我會使用第一種語法以方便對齊參數值。這種方法與前一種方法的主要差異是,GMT 會紀錄改變的預設值,只要紀錄不被覆蓋或刪除,**改變的參數對接下來的所有指令都有效**。第一次下達 ``set`` 指令時,GMT 會在當前目錄下建立 ``gmt.conf`` 檔案,並把所有更動儲存在內。之後所有的 GMT 指令都會讀取此檔案,這就是為什麼使用 ``set`` 設定參數會有永久性效用的原因。 In this tutorial, I will use the first syntax for a better alignment of parameter values. The main difference between this method and the previous method is that GMT records the change. As long as the record is not overwritten or deleted, **the modified parameter setting is valid for all subsequent commands**. When the ``set`` command is issued for the first time, GMT will create a ``gmt.conf`` file in the current directory and store all changes in it. All subsequent GMT commands will read this file, which is why using ``set`` has a permanent effect. CC-BY-4.0 +如果你的資料夾中已經有了上一次繪圖時產生的 ``gmt.conf``,而你又不想讓上一次的設定選項「干擾」到你這一次要畫的地圖,則你可以簡單的把 ``gmt.conf`` 刪掉,這樣 GMT 會重新使用系統預設值,然後就可以從頭使用 ``set`` 來設定新的繪圖參數。 "It is possible to have the ``gmt.conf`` file in your folder that comes from your previous mapping session. If you don’t want the previous parameter settings to ""interfere"" with the map you are drawing this time, you can simply delete ``gmt.conf``, so that GMT will reuse the system default values, and then you can use ``set`` from the beginning to modify mapping parameters." CC-BY-4.0 +介紹完 ``set`` 後,讓我們馬上來做個測試。在剛剛目標地圖下半部的腳本中加入此指令: Now we know how ``set`` works, and let's take a test right away. Add this command to the script we use to plot the lower half of the target map: CC-BY-4.0 +"land_color=""#CEB9A0"" +gmt set MAP_FRAME_TYPE plain +# MAP_FRAME_TYPE:地圖邊框樣式。預設是 fancy,就是上圖的黑白相間邊框。改成 plain 的話,邊框會變成最基本的樣式。 + +gmt begin ulaanbaatar_seattle png + gmt basemap -R70/270/30S/70N -JM13c -B+tMercator + gmt coast -Dl -A1000 -G$land_color -N1/thick,60 -Ba40f20g20 +gmt end" "land_color=""#CEB9A0"" +gmt set MAP_FRAME_TYPE plain +# MAP_FRAME_TYPE: border style of the map. The default is fancy, which is the black-and-white border as shown above. We change it to plain for rendering the most basic border style. + +gmt begin ulaanbaatar_seattle png + gmt basemap -R70/270/30S/70N -JM13c -B+tMercator + gmt coast -Dl -A1000 -G$land_color -N1/thick,60 -Ba40f20g20 +gmt end" CC-BY-4.0 +可以看出地圖的邊緣從斑馬框變成一條線了。運用相同的方式,我們還要逐一修改以下預設參數: You can see that the map frame has turned from a zebra pattern into a simple line. Now we'll modify the following default parameters one by one using the same way: CC-BY-4.0 +``FONT_TITLE``:標題字型。在 GMT 中,**字型與畫筆類似,由三個部份組成**:``尺寸,字型,顏色``。「尺寸」可為任意數值,預設單位為點 (points);「樣式」則可參考 `PostScript 的字型樣式表 `_,可以使用字型的代號或是字型的名稱來表示。「顏色」則是 GMT 通用的顏色格式。我們想要的設定是 ``30,Bookman-Demi,#0D057A`` (30 點字的 Bookman-Demi,顏色是 #0D057A)。 "``FONT_TITLE``: Title font. In GMT, the **font string is similar to a pen string, which consists of three parts**: ``size, style, color``. ""Size"" can be any value with a default unit of points. ""Style"" refers to the `PostScript font table `_, which can be assigned by the font name or the font number. ""Color"" is a generic color format for GMT. The setting we want is ``30,Bookman-Demi,#0D057A`` (30-pt Bookman-Demi with the color of #0D057A)." CC-BY-4.0 +``FONT_ANNOT_PRIMARY``:座標軸主格點標示的字型,使用 ``12p,20,#0D057A`` (12點字的 Bookman-LightItalic,顏色與標題一樣)。 ``FONT_ANNOT_PRIMARY``: The font for the primary grid tick labels. We use ``12p,20,#0D057A`` (12-pt Bookman-LightItalic; the color is the same as the title). CC-BY-4.0 +``FORMAT_GEO_MAP``:(地理作圖的) 座標刻度標示的格式,使用英文代號的搭配組合表示,``d`` 代表度,``m`` 代表分,``s`` 代表秒,``F`` 代表數值後面會加的「NEWS」後綴符號,詳細設定可\\ `在此查閱 `_。我們要使用的是 ``dddF``,如此一來可令所有座標只以至多三位數的度來表示,並搭配後綴符號。 "``FORMAT_GEO_MAP``: format of (geographical) coordinates on the map. We use a combination code names here: ``d`` stands for degree, ``m`` stands for minutes, ``s`` stands for seconds, and ``F`` represents the ""NEWS"" suffix that will be added after the value. The detailed documentation is `available here `_. We use ``dddF``, which means to only show degrees with up to three digits as well as the direction suffix." CC-BY-4.0 +``MAP_GRID_CROSS_SIZE_PRIMARY``:地圖格線的十字交叉符號大小。使用 ``8p``。 ``MAP_GRID_CROSS_SIZE_PRIMARY``: The size of the grid cross on the map. We use ``8p``. CC-BY-4.0 +``MAP_GRID_PEN_PRIMARY``:地圖格線的畫筆屬性。使用 ``thinner,#ED99F0``。 ``MAP_GRID_PEN_PRIMARY``: the pen attribute of the map grid. We use ``thinner,#ED99F0``. CC-BY-4.0 +``MAP_TICK_PEN_PRIMARY``:地圖座標刻度的畫筆屬性。使用 ``thicker,black``。 ``MAP_TICK_PEN_PRIMARY``: The pen attribute of the map ticks. We use ``thicker, black``. CC-BY-4.0 +``MAP_TITLE_OFFSET``:地圖標題與座標軸刻度的垂直距離。使用 ``0.5c``。 ``MAP_TITLE_OFFSET``: The vertical distance between the map title and the frame. We use ``0.5c``. CC-BY-4.0 +``MAP_ANNOT_OBLIQUE``:座標軸刻度的「擺放模式」。在上圖中,經度和緯度的刻度都是水平顯示的,我們要使用的設定代號是 ``32``,意謂著「經度保持原樣,緯度與地圖的邊框平行顯示」。 "``MAP_ANNOT_OBLIQUE``: the ""placement mode"" of the map tick labels. In the above figure, the labels for longitude and latitude are displayed horizontally. Here we want to use the code ``32``, which means that ""longitude remains the same format, and latitude is vertically displayed along with the map border""." CC-BY-4.0 +``PS_PAGE_COLOR``:紙張的底色。使用 ``ivory`` (象牙色)。 ``PS_PAGE_COLOR``: The background color of the paper. We ``ivory``. CC-BY-4.0 +因此,在原腳本中 ``set`` 的設定可以擴展成: Therefore, the ``set`` command in the original script can be expanded to: CC-BY-4.0 +"# (前略) +gmt set FONT_ANNOT_PRIMARY 12p,20,#0D057A \\ + FONT_TITLE 30,Bookman-Demi,#0D057A \\ + FORMAT_GEO_MAP dddF \\ + MAP_ANNOT_OBLIQUE 32 \\ + MAP_FRAME_TYPE plain \\ + MAP_GRID_CROSS_SIZE_PRIMARY 8p \\ + MAP_GRID_PEN_PRIMARY thinner,#ED99F0 \\ + MAP_TICK_PEN_PRIMARY thicker,black \\ + MAP_TITLE_OFFSET 0.5c \\ + PS_PAGE_COLOR ivory +# 注意我在每一行結尾使用了 ""\\"" 符號,意味著下一行仍然是 gmt set 的內容。 +# (後略)" "# ... (skipped) +gmt set FONT_ANNOT_PRIMARY 12p,20,#0D057A \\ + FONT_TITLE 30,Bookman-Demi,#0D057A \\ + FORMAT_GEO_MAP dddF \\ + MAP_ANNOT_OBLIQUE 32 \\ + MAP_FRAME_TYPE plain \\ + MAP_GRID_CROSS_SIZE_PRIMARY 8p \\ + MAP_GRID_PEN_PRIMARY thinner,#ED99F0 \\ + MAP_TICK_PEN_PRIMARY thicker,black \\ + MAP_TITLE_OFFSET 0.5c \\ + PS_PAGE_COLOR ivory +# Note that I used ""\\"" at the end of each line, which continues the gmt set command to the next line. +# ... (skipped)" CC-BY-4.0 +有許多參數名稱都有 ``PRIMARY``,這是由於 GMT 的某些邊框 (尤其是 ``fancy`` 類型的邊框) 會使用不同的設定來指定主格線 (刻度) 與副格線 (刻度)。在我們的例子中,只設定了主格線,副格線皆已省略。你也可以換成 ``fancy`` 類型的邊框,指定副格線的樣式 (帶有 ``SECONDARY`` 的參數名稱),看看出圖會是什麼樣的感覺! Many parameters have ``PRIMARY`` in their names because some GMT map frames (especially the ``fancy`` type frames) use different settings to render primary gridlines (and ticks) and secondary gridlines (and ticks). In our case, we only set the primary main gridlines and omit the secondary gridlines. You can also change to a ``fancy`` type map frame and specify the style of secondary gridlines (by setting the parameters with ``SECONDARY`` in their name) to see what the figure looks like! CC-BY-4.0 +如要使用不是 GMT 預先定義的 PostScript 字型,請參閱 `這個例子 `_。 To use a PostScript font that is not predefined by GMT, see `this example < https://docs.generic-mapping-tools.org/6.0/gallery/ex31.html>`_. CC-BY-4.0 +以上腳本出圖如下: Here's the output figure: CC-BY-4.0 +大部分的改動都如我們所預期:所有的字體樣式都換了、地圖邊框改了、顏色和格線也換成比較舒服的搭配。接下來讓我們補完這張地圖上的城市位置和兩條不同的路徑。由於在 ``coord.txt`` 中,座標欄位是「先緯度再經度」,因此在使用 ``plot`` 時,需要加上 ``-:`` 選項,「告訴」GMT 第一欄是 Y 值,第二欄是 X 值。``plot`` 在地圖上畫線時的預設模式是「畫出大圓路徑」,如果加上 ``-A`` 選項,可以改成「畫出投影系統中的直線路徑」,在麥卡托投影中,這條路徑就是恆向線。因此,運用 ``plot`` 與 ``text``,就可以畫出以上目標,並且標注兩條路徑的名稱: "Most of the changes are as we expected: all font styles have been changed, the map frame has been replaced, colors and gridlines now look much better. Next, let us complete the city locations and two different paths on this map. In ``coord.txt``, the coordinate field order is ""latitude, longitude"". Hence, to use ``plot`` you need to add the ``-:`` option ""telling"" GMT that the first column is Y and the second column is X. The default mode of ``plot`` for drawing a line on the map is to ""draw the great circle route."" If you add the ``-A`` option, you can override the rule and ""draw the straight path in the projected map system"". For Mercato projection, this straight path is exactly the rhumb line. Therefore, we use ``plot`` and ``text`` to plot these items and make the names of the two lines:" CC-BY-4.0 +"# ==== 設定變數 ==== +input_xy=""coord.txt"" +land_color=""#CEB9A0"" # 陸域填色 +rl_color=""#FF0073"" # 恆向線顏色 +gc_color=""#0044FF"" # 大圓路徑顏色 + +# ==== 設定作圖參數 ==== +gmt set FONT_ANNOT_PRIMARY 12p,20,#0D057A \\ + FONT_TITLE 30,Bookman-Demi,#0D057A \\ + FORMAT_GEO_MAP dddF \\ + MAP_ANNOT_OBLIQUE 32 \\ + MAP_FRAME_TYPE plain \\ + MAP_GRID_CROSS_SIZE_PRIMARY 8p \\ + MAP_GRID_PEN_PRIMARY thinner,#ED99F0 \\ + MAP_TICK_PEN_PRIMARY thicker,black \\ + MAP_TITLE_OFFSET 0.5c \\ + PS_PAGE_COLOR ivory + +# ==== 開始繪圖 ==== +gmt begin ulaanbaatar_seattle png + gmt basemap -R70/270/30S/70N -JM13c -B+tMercator + gmt coast -Dl -A1000 -G$land_color -N1/thick,60 -Ba40f20g20 --MAP_GRID_PEN_PRIMARY=thicker + # 調整 MAP_GRID_PEN_PRIMARY 讓十字符號粗一點 + gmt plot $input_xy -: -A -W1p,$rl_color # 恆向線 + gmt plot $input_xy -: -W1p,$gc_color # 大圓路徑 + gmt plot $input_xy -: -Sa0.4c -Gblack # 城市的位置,-Sa0.4c 是外接圓為 0.4 公分的星形符號。 + # 以下是兩條線的說明文字 + echo ""174 41 Rhumb Line"" | gmt text -F+f,18,$rl_color + echo ""174 61 Great Circle"" | gmt text -F+f,18,$gc_color +gmt end" "# ==== Set variables ==== +input_xy=""coord.txt"" +land_color=""#CEB9A0"" # color for land area +rl_color=""#FF0073"" # color for rhumb line +gc_color=""#0044FF"" # color for great circle line + +# ==== Set map parameters ==== +gmt set FONT_ANNOT_PRIMARY 12p,20,#0D057A \\ + FONT_TITLE 30,Bookman-Demi,#0D057A \\ + FORMAT_GEO_MAP dddF \\ + MAP_ANNOT_OBLIQUE 32 \\ + MAP_FRAME_TYPE plain \\ + MAP_GRID_CROSS_SIZE_PRIMARY 8p \\ + MAP_GRID_PEN_PRIMARY thinner,#ED99F0 \\ + MAP_TICK_PEN_PRIMARY thicker,black \\ + MAP_TITLE_OFFSET 0.5c \\ + PS_PAGE_COLOR ivory + +# ==== Begin to plot ==== +gmt begin ulaanbaatar_seattle png + gmt basemap -R70/270/30S/70N -JM13c -B+tMercator + gmt coast -Dl -A1000 -G$land_color -N1/thick,60 -Ba40f20g20 --MAP_GRID_PEN_PRIMARY=thicker + # We adjust MAP_GRID_PEN_PRIMARY so the cross signs can be a bit thicker + gmt plot $input_xy -: -A -W1p,$rl_color # Rhumb line + gmt plot $input_xy -: -W1p,$gc_color # Great circle path + gmt plot $input_xy -: -Sa0.4c -Gblack # location of the cities. -Sa0.4c is a star symbol which can be circumscribed by a 0.4 cm diameter circle. + # The following are the labels for the two lines + echo ""174 41 Rhumb Line"" | gmt text -F+f,18,$rl_color + echo ""174 61 Great Circle"" | gmt text -F+f,18,$gc_color +gmt end" CC-BY-4.0 +如此一來,目標地圖的下半部就完成了! In this way, the lower half of the target map is complete! CC-BY-4.0 +接下來讓我們進入上半部,蘭伯特投影的地圖。為了不讓地圖彼此重疊,我們必須把第二個地圖呈現的位置往上移。GMT 的通用選項 ``-X`` 和 ``-Y`` 就是用來設定地圖的相對位置,它的用法為 Next, let us switch to the upper panel with a Lambert projection map. In order to prevent the panels from overlapping each other, we must place this second map at a different position on the figure; in this case, it's moving up. The GMT general options ``-X`` and ``-Y`` are used to set the relative position of the map panels. Its syntax is CC-BY-4.0 +"'-X水平偏移量 (向右為正) +-Y垂直偏移量 (向上為正)'" "'-Xhorizontal_offset (positive to the right) +-Yvertical_offset (positive to the north)'" CC-BY-4.0 +在這裡我們只需要垂直偏移,因此使用 ``-Y`` 即可。例如 ``-Y12c`` 就是向上偏移 12 公分。或是你也可以使用 ``h`` 以及 ``w`` 代表前一張地圖的作圖高度與寬度,例如 ``-Yh+3c`` 就是向上偏移上一張地圖的高度再加 3 公分。``-X`` 和 ``-Y`` 會永久改變地圖在紙張上呈現的位置,因此只需要在\\ **下一張地圖的第一個繪圖指令**\\ 附上這些選項就可以以了。 Here we only need the vertical offset and thus use ``-Y``. For example, ``-Y12c`` is an offset of 12 cm upward. You can also use ``h`` and ``w`` to represent the height and width of the previous map. For example, ``-Yh+3c`` means to offset the height of the previous map plus 3 cm. ``-X`` and ``-Y`` permanently change the drawing position on the figure, so you only need to use these options once at **the first plotting command for the next map**. CC-BY-4.0 +接下來我們來看看蘭伯特等積方位投影使用的 ``-R`` 與 ``-J`` 選項。此投影法限定使用全球的作圖範圍,也就是 ``-R-180/180/-90/90``。你也可以使用比較短的特殊代號 ``-Rg``,它的效果與前者相同。``-J`` 語法則為: Now let's take a look at the ``-R`` and ``-J`` options for the Lambert azimuthal equal-area projection. This projection needs to have a global mapping extent, which is ``-R-180/180/-90/90``. You can also use the shorter code ``-Rg`` for the same setting. The ``-J`` syntax is: CC-BY-4.0 +'-JA中心點經度/中心點緯度/尺寸' '-JAcenter_longitude/center_latitude/mapsize' CC-BY-4.0 +選擇烏蘭巴托的座標當作投影的中心點,就可以畫出地圖、海岸線、大圓路徑與城市位置: Specify the coordinates of Ulaanbaatar as the center of the projection, and you can draw the map, coastline, great circle route, and city locations: CC-BY-4.0 +"# (前略) +# ==== 開始繪圖 ==== +gmt begin ulaanbaatar_seattle png + # (上述麥卡托地圖的部份) + # ==== 繪圖 (蘭伯特) ==== + gmt basemap -Rg -JA106:55/47:55/13c -Yh+3c -B+tLambert --MAP_TITLE_OFFSET=0c # 把標題與地圖邊框弄靠近一點 + gmt coast -Dl -A1000 -G$land_color -N1/thick,60 -Bxg60 -Byg30 --MAP_GRID_CROSS_SIZE_PRIMARY=0p + # 我們不要十字符號出現在此地圖中所以 MAP_GRID_CROSS_SIZE_PRIMARY 設為 0 + gmt plot $input_xy -: -W1p,$gc_color # 大圓路徑 + gmt plot $input_xy -: -Sa0.4c -Gblack # 城市位置 + +gmt end" "# ... (Skipped) +# ==== Begin to plot ==== +gmt begin ulaanbaatar_seattle png + # ... (Here's the code for the Mercator map panel) + # ==== Plot (Lambert) ==== + gmt basemap -Rg -JA106:55/47:55/13c -Yh+3c -B+tLambert --MAP_TITLE_OFFSET=0c # We put the map title a bit closer to the map frame + gmt coast -Dl -A1000 -G$land_color -N1/thick,60 -Bxg60 -Byg30 --MAP_GRID_CROSS_SIZE_PRIMARY=0p + # We don't want crosshair marks on the map so MAP_GRID_CROSS_SIZE_PRIMARY is set to 0 + gmt plot $input_xy -: -W1p,$gc_color # Great circle path + gmt plot $input_xy -: -Sa0.4c -Gblack # City locations + +gmt end" CC-BY-4.0 +注意 GMT 無法透過 ``-B`` 選項為蘭伯特地圖設定座標刻度,我們稍後得自行使用 ``text`` 額外標上去。現在烏蘭巴托已經被置於地圖正中間了,這時大圓路徑在地圖上就是一直線前往西雅圖,如果我們把 ``-A`` 選項打開,也只會得到相同的路徑。那麼,**該如何畫出在這張地圖上的恆向線?**\\ 由於西雅圖和烏蘭巴托的緯度非常相近,因此恆向線相當於沿著緯線前進的線段。對於這種狀況,我們可以使用 ``-Ap`` 選項,強制讓兩點之間沿著緯線和經線連接: Note that GMT cannot use the ``-B`` option to plot tick labels for a Lambert map. We will have to use ``text`` to add them later. Now Ulaanbaatar has been placed in the center of the map, and in this case, the great circle path is already a straight line to Seattle. If we turn on the ``-A`` option, we will just get the same path. **How do you plot the rhumb line on this map?** Since Seattle and Ulaanbaatar have very similar latitudes, the rhumb line is essentially a segment that goes along the latitude line. To tackle this situation, we can use the ``-Ap`` option to force connecting two points along the latitude and longitude lines: CC-BY-4.0 +gmt plot $input_xy -: -Ap -W1p,$rl_color # (第二個地圖上的) 恆向線 gmt plot $input_xy -: -Ap -W1p,$rl_color # Rhumb line (for the second map) CC-BY-4.0 +以上繪製恆向線的技巧在兩地處在不同的緯度下無法適用。更一般性的作法是呼叫 GMT 中一個多功能的指令:``project``。這個指令可以用來進行座標轉換或是產生在某個特定的座標系統下的兩點間移動路徑。使用 ``project`` 在平面直角座標下產生直線路徑,再送給 ``plot`` 繪圖,就可以畫出恆向線: The above technique of drawing rhumb lines cannot apply to two places with different latitudes. A more general approach is to call a multifunctional command in GMT: ``project``. This command can perform the coordinate transformation or generate a path connecting two points in a specific coordinate system. So we use ``project`` to generate a straight path in the Cartesian system, and then we ``plot`` this path for the rhumb line: CC-BY-4.0 +"gmt project -C106.92/47.92 -E237.67/47.61 -G10 -N | gmt plot -W1p,$rl_color # (第二個地圖上的) 恆向線 +# -C: 起點座標 (烏蘭巴托) +# -E: 終點座標 (西雅圖, 經度要比烏蘭巴托大,因此加上 360) +# -G: 每個取樣點的距離 (單位與起終點座標相同) +# -N: 設定座標系為平面直角座標" "gmt project -C106.92/47.92 -E237.67/47.61 -G10 -N | gmt plot -W1p,$rl_color # Rhumb line (for the second map) +# -C: Starting point coordinates (Ulaanbaatar) +# -E: Ending point coordinates (Seattle. We add 360 to its longitude to force this line to go east from Ulaanbaatar) +# -G: Distance of each sampling point along the line (the unit is the same as the coordinates) +# -N: Set the coordinate system to Cartesian" CC-BY-4.0 +歡迎自行使用此行取代腳本中畫恆向線的指令。有關 ``project`` 指令的詳細說明,請參閱「\\ :doc:`contour_and_profile`\\ 」。 You are welcome to replace the code for the rhumb line in the original script with this line. For more information about the ``project`` command, please go to :doc:`contour_and_profile`. CC-BY-4.0 +本地圖的最後一步,就是替兩條線與經緯格線加上文字標籤。換 ``text`` 上場了!這次要標的文字比較複雜,因為每個標籤的角度都不一樣,使用 ``echo`` 一一指定的話會變得有點麻煩。幸好,``text`` 和 ``plot`` 一樣,都可以利用重導向符號 ``<<`` 一次輸入以上這些不同資訊。它的具體語法為: The last step for this map is to add text labels to the two lines and the latitude and longitude gridlines. It's showtime for ``text``! In this case, the text to be labeled is more complicated because each of them needs to have a different tilting angle. It would be a pain in the neck to specify this one at a time using ``echo``. Fortunately, we can use the redirection operator ``<<`` for ``text`` and enter different information at once, which is similar to what we do with ``plot``. Specifically, its syntax is: CC-BY-4.0 +"gmt text -F+欄位a+欄位b+.... [其他選項] << EOF +第一欄(固定為X) 第二欄(固定為Y) 第三欄(欄位a) 第四欄(欄位b) ... 最後一欄(固定為標籤文字) +... ... ... ... ... ... +... ... ... ... ... ... +EOF" "gmt text -F+field_a+field_b+.... [other options] << EOF +field_1(X) field_2(Y) field_3(field_a) field_4(field_b) ... last_field (label text) +... ... ... ... ... ... +... ... ... ... ... ... +EOF" CC-BY-4.0 +也就是說,``text`` 要求輸入最少為 3 欄 (X、Y、標籤文字),而透過 ``-F`` 選項,可以指定更多的欄位。如果要加上經緯格線的文字標籤,我們可以使用 ``-F+a``,如此一來第 3 欄就會是每個文字的角度 (從水平開始往逆時針旋轉),標籤文字則會被擠到第 4 欄,如下所示: In other words, ``text`` requires that the input has at least 3 fields (X, Y, label text). If there are more fields, you can use the ``-F`` option to specify what the extra fields mean. For the text labels of the latitudes and longitudes, we use ``-F+a`` so that the third column becomes the tilting angle of each text (0 is horizontal, rotating counterclockwise), and the label text is read from column 4, as shown below: CC-BY-4.0 +"gmt text -F+a << ANNOTEND +106.92 -30 0 30@.S +106.92 30 0 30@.N +60 15 70 60@.E +180 15 305 180@. +ANNOTEND +# 經度 緯度 角度 文字 +# ""@."" 會被解讀成度數符號" "gmt text -F+a << ANNOTEND +106.92 -30 0 30@.S +106.92 30 0 30@.N +60 15 70 60@.E +180 15 305 180@. +ANNOTEND +# lon lat angle text +# ""@."" would be rendered as a degree sign" CC-BY-4.0 +如果要加上大圓路徑和恆向線的標籤,我們除了要指定旋轉角度外,也要指定不同的字型。在前面的麥卡托地圖中,指定字型的方式是 ``-F+f字型樣式`` ,如果不給 ``字型樣式`` 的話,就代表 ``text`` 必需要在輸入資料中尋找對應的欄位。因此,我們也可使用 ``-F+a+f`` 來指定第 3 欄為角度、第 4 欄為字型樣式,而標籤文字這次則被放到了第 5 欄: To add labels for the great circle path and the rhumb line, we want to specify a different font in addition to the tilting angle. For the previous Mercator map, we specify a font by ``-F+fstyle``. If ``style`` is omitted in the string, ``text`` will find a certain field from the input for the font style. Therefore, we can use ``-F+a+f`` to specify that the third column is tilting angle, the fourth column is the font style, and the label text is the fifth column this time: CC-BY-4.0 +"gmt text -F+a+f << LABELEND +180 40 58 ,Bookman-DemiItalic,$rl_color Rhumb Line +180 80 58 ,Bookman-DemiItalic,$gc_color Great Circle +LABELEND +# 經度 緯度 角度 字型樣式 文字" "gmt text -F+a+f << LABELEND +180 40 58 ,Bookman-DemiItalic,$rl_color Rhumb Line +180 80 58 ,Bookman-DemiItalic,$gc_color Great Circle +LABELEND +# lon lat angle font text" CC-BY-4.0 +把以上兩段指令加在腳本內 ``# ==== 繪圖 (蘭伯特) ====`` 的段落中,就能加上我們想要的標籤。 Add the above two code snippets to the ``# ==== Plot (Lambert) ====`` section in the script, and you can create the labels we want. CC-BY-4.0 +恭喜!我們終於完成本章目標的地圖了。最後再次提醒:使用 ``set`` 修改的預設參數,都會被存在 ``gmt.conf`` 中。如果你下次要在同一個資料夾作圖,但是又不想使用這次的設定,那麼在地圖完成後,請自行刪除 ``gmt.conf`` 或是把刪除指令放在腳本中的最後一行: Congratulations! The map we want for this chapter is finally done. Lastly, let me bring this up again: the map parameters modified using ``set`` will be stored in ``gmt.conf``. If you want to make some maps in the same folder next time but do not want to use the same settings from this time, you can manually delete ``gmt.conf`` after you are done with this map or put the delete command in the last line of the script: CC-BY-4.0 +"# (前略) +gmt end +rm -rf gmt.conf # <---- 消除舊的組態設定檔" "# ... (Skipped) +gmt end +rm -rf gmt.conf # <---- remove old map configuration file" CC-BY-4.0 +"# ==== 設定變數 ==== +input_xy=""coord.txt"" +land_color=""#CEB9A0"" +rl_color=""#FF0073"" # 恆向線顏色 +gc_color=""#0044FF"" # 大圓路徑顏色 +# 把兩個城市的 xy 座標寫入 $input_xy 檔案中 +# 如果你已經下載了 coord.txt,以下四行可以註解掉。 +xy_ulaanbaatar=""47:55:0N, 106:55:0E"" # 烏蘭巴托的座標 +xy_seattle=""47:36:35N, 122:19:59W"" # 西雅圖的座標 +echo $xy_ulaanbaatar > $input_xy +echo $xy_seattle >> $input_xy + +# ==== 設定作圖參數 ==== +gmt set FONT_ANNOT_PRIMARY 12p,20,#0D057A \\ + FONT_TITLE 30,Bookman-Demi,#0D057A \\ + FORMAT_GEO_MAP dddF \\ + MAP_ANNOT_OBLIQUE 32 \\ + MAP_FRAME_TYPE plain \\ + MAP_GRID_CROSS_SIZE_PRIMARY 8p \\ + MAP_GRID_PEN_PRIMARY thinner,#ED99F0 \\ + MAP_TICK_PEN_PRIMARY thicker,black \\ + MAP_TITLE_OFFSET 0.5c \\ + PS_PAGE_COLOR ivory + +# ==== 開始繪圖 ==== +gmt begin ulaanbaatar_seattle_gmt6 png + + # ==== 下圖 (麥卡托) ==== + gmt basemap -R70/270/30S/70N -JM13c -B+tMercator + gmt coast -Dl -A1000 -G$land_color -N1/thick,60 -Ba40f20g20 --MAP_GRID_PEN_PRIMARY=thicker + gmt plot $input_xy -: -A -W1p,$rl_color # 恆向線 + gmt plot $input_xy -: -W1p,$gc_color # 大圓路徑 + gmt plot $input_xy -: -Sa0.4c -Gblack + echo ""174 41 Rhumb Line"" | gmt text -F+f,18,$rl_color + echo ""174 61 Great Circle"" | gmt text -F+f,18,$gc_color + + # ==== 上圖 (蘭伯特) ==== + gmt basemap -Rg -JA106:55/47:55/13c -Yh+3c -B+tLambert --MAP_TITLE_OFFSET=0c + gmt coast -Dl -A1000 -G$land_color -N1/thick,60 -Bxg60 -Byg30 --MAP_GRID_CROSS_SIZE_PRIMARY=0p + gmt plot $input_xy -: -Ap -W1p,$rl_color # 恆向線 + gmt plot $input_xy -: -W1p,$gc_color # 大圓路徑 + gmt plot $input_xy -: -Sa0.4c -Gblack + + gmt text -F+a << ANNOTEND +106.92 -30 0 30@.S +106.92 30 0 30@.N +60 15 70 60@.E +180 15 305 180@. +ANNOTEND + + gmt text -F+a+f << LABELEND +180 40 58 ,Bookman-DemiItalic,$rl_color Rhumb Line +180 80 58 ,Bookman-DemiItalic,$gc_color Great Circle +LABELEND + +gmt end + +# rm -rf gmt.conf # 消除舊的 GMT 參數檔" "# ==== Set variables ==== +input_xy=""coord.txt"" +land_color=""#CEB9A0"" +rl_color=""#FF0073"" # color for rhumb line +gc_color=""#0044FF"" # color for great circle line +# Write the xy coordinates of the two cities into the $input_xy file +# If you have downloaded coord.txt, then you can comment the following four lines. +xy_ulaanbaatar=""47:55:0N, 106:55:0E"" # Ulaanbaatar lat/lon +xy_seattle=""47:36:35N, 122:19:59W"" # Seattle lat/lon +echo $xy_ulaanbaatar > $input_xy +echo $xy_seattle >> $input_xy + +# ==== Set map parameters ==== +gmt set FONT_ANNOT_PRIMARY 12p,20,#0D057A \\ + FONT_TITLE 30,Bookman-Demi,#0D057A \\ + FORMAT_GEO_MAP dddF \\ + MAP_ANNOT_OBLIQUE 32 \\ + MAP_FRAME_TYPE plain \\ + MAP_GRID_CROSS_SIZE_PRIMARY 8p \\ + MAP_GRID_PEN_PRIMARY thinner,#ED99F0 \\ + MAP_TICK_PEN_PRIMARY thicker,black \\ + MAP_TITLE_OFFSET 0.5c \\ + PS_PAGE_COLOR ivory + +# ==== Begin to plot ==== +gmt begin ulaanbaatar_seattle_gmt6 png + + # ==== Bottom panel (Mercator) ==== + gmt basemap -R70/270/30S/70N -JM13c -B+tMercator + gmt coast -Dl -A1000 -G$land_color -N1/thick,60 -Ba40f20g20 --MAP_GRID_PEN_PRIMARY=thicker + gmt plot $input_xy -: -A -W1p,$rl_color # Rhumb line + gmt plot $input_xy -: -W1p,$gc_color # Great circle path + gmt plot $input_xy -: -Sa0.4c -Gblack + echo ""174 41 Rhumb Line"" | gmt text -F+f,18,$rl_color + echo ""174 61 Great Circle"" | gmt text -F+f,18,$gc_color + + # ==== Top panel (Lambert) ==== + gmt basemap -Rg -JA106:55/47:55/13c -Yh+3c -B+tLambert --MAP_TITLE_OFFSET=0c + gmt coast -Dl -A1000 -G$land_color -N1/thick,60 -Bxg60 -Byg30 --MAP_GRID_CROSS_SIZE_PRIMARY=0p + gmt plot $input_xy -: -Ap -W1p,$rl_color # Rhumb line + gmt plot $input_xy -: -W1p,$gc_color # Great circle path + gmt plot $input_xy -: -Sa0.4c -Gblack + + gmt text -F+a << ANNOTEND +106.92 -30 0 30@.S +106.92 30 0 30@.N +60 15 70 60@.E +180 15 305 180@. +ANNOTEND + + gmt text -F+a+f << LABELEND +180 40 58 ,Bookman-DemiItalic,$rl_color Rhumb Line +180 80 58 ,Bookman-DemiItalic,$gc_color Great Circle +LABELEND + +gmt end + +# rm -rf gmt.conf # Remove existing GMT parameter settings" CC-BY-4.0 +「繪製大圓路徑與恆向線。版面與地圖框線、標示的外貌與位置皆經過微調,先畫下圖 (麥卡托投影) 再畫上圖 (蘭伯特投影)。在腳本中也額外標上了上圖的格線經緯度。」 """Plot great circle routes and rhumb lines. The layout, map frame, mark type, and mark locations have been fine-tuned. Draw the bottom panel (Mercator projection) first and then draw the upper panel (Lambert projection). We also add several additional lines in the script to label the latitude and longitude lines in the upper panel.""" CC-BY-4.0 +畫出跟下圖越相似越好的赤道幾內亞 (Equatorial Guinea) 地圖\\ [#]_,但不用標上道路、鄉鎮市名稱、地理名稱與比例尺,紅色圓圈與連接紅色圓圈的黑色虛線則須標明,喀麥隆 (Cameroon)、加彭 (Gabon) 與聖多美普林西比 (São Tomé e Príncipe) 的國名也必須標出,地圖中的五個大島嶼的名稱也要顯示在地圖上。���圖左上方的位置示意圖,可看待為第二張地圖,利用 ``-X`` 與 ``-Y`` 選擇位置並疊在第一張地圖上。 Make a map of Equatorial Guinea as similar to the figure below [#]_ as possible. You do not need to place roads, cities, place names, and scales, but the red circles and the black dotted lines connecting them must be plotted. Country names (Cameroon, Gabon, and São Tomé e Príncipe) have to be placed on the map too. as well as the names of the five large islands. The map inset on the top left of the main map can be treated as the second map. Use ``-X`` and ``-Y`` to select the location and overlay it on the main map. CC-BY-4.0 +加入地圖元素 Add Map Elements CC-BY-4.0 +GMT / PyGMT 簡介與安裝 GMT / PyGMT Introduction and Installation CC-BY-4.0 +[GMT][GMT-link] 是什麼? What is [GMT][GMT-link]? CC-BY-4.0 +[GMT][GMT-link] 的全名是 Generic Mapping Tools,為一套多功能的製圖工具。這套軟體始於 1988 年,由當時就讀於拉蒙特-杜赫第地球觀測站 (Lamont-Doherty Earth Observatory) 的 Pål (Paul) Wessel 和 Walter H. F. Smith 設計製作,並在 1991 年公開發表第一版。[^1] 軟體釋出後即收到廣大迴響,這些稱讚與建議成了兩位作者 (與其後加入開發團隊的所有人員) 繼續更新的原動力。三十多年過去了,GMT 在 2019 年的 11 月已經更新到第 6 版 [^2],在地理繪圖領域享有一席之地,更是許多領域,如地球物理學、海洋科學等等,一定會接觸到的軟體之一。 Generic Mapping Tools, or [GMT][GMT-link] for short, is a software package for geographical mapping and other related tasks. The software was initiated in 1988 by Pål (Paul) Wessel and Walter H. F. Smith, who were graduate students at Lamont-Doherty Earth Observatory. The first version of GMT was released in 1991 [^1] and received a lot of positive feedback on how useful and powerful the package could be, which has motivated two authors and the whole GMT development team to continue the project. More than 30 years later, in November 2019, the development team released the sixth edition of GMT [^2], which would continue to take a major role in geographical mapping. Now GMT is a popular toolbox for plotting scientific data for academic fields such as geophysics or oceanography. CC-BY-4.0 +GMT 身為「通用」的製圖工具,當然可以進行一般性的科學繪圖,大部分你想得到的圖表種類,都可以利用 GMT 內附的指令來完成。但本軟體真正的強大之處,還是在於地理資料的處理與地圖的繪製。GMT 內建許多和地理資訊系統 (GIS) 有關的演算法,讓使用者可以輕鬆的藉由一個個指令,就完成精美且高解析度的地圖。輸出的圖檔支援多種格式,包括向量化的格式檔案如 EPS 或 PDF 等,非常容易進行更多的編修。 As a “generic” mapping toolbox, GMT is of course capable of making different types of scientific plots using its built-in commands. However, what really makes this package so powerful is that GMT is very good at processing geographical data and visualizing them in the right way. GMT includes a lot of GIS algorithms, and a user just needs to enter a few console commands for making some beautiful and high-resolution maps. These maps support multiple formats, including vectorized files such as EPS and PDF, allowing users to make further edits with ease. CC-BY-4.0 +[PyGMT][PyGMT-link] 呢? And what is [PyGMT][PyGMT-link]? CC-BY-4.0 +[PyGMT][PyGMT-link] 其實就是把 GMT 重新包裝,讓所有 GMT 內的工具都可以透過 Python 這個程式語言以模組的方式來使用。除了讓原本就熟悉 Python 的人快速上手 GMT 外,遠程目標是與 Python 的其他資料科學模組一同連動,構築以 Python 進行科學資料分析的豐富環境。目前 PyGMT 已經支援了 Numpy、Pandas 和 Xarray 專有的資料格式,並且也可透過 Jupyter 環境進行互動性資料繪圖。[^3] [PyGMT][PyGMT-link] is essentially a “Pythonized GMT package.” PyGMT rewraps the GMT so one can access all GMT tools as a Python module. In addition to attracting more potential users, the long-term of PyGMT is to build a Python ecosystem for scientific data analysis, together with other data science modules in Python. As of now, PyGMT already supports some data formats found in Numpy, Pandas, and Xarray, and can interactively draw your data using the Jupyter environment. [^3] CC-BY-4.0 +PyGMT 是由科學社群發起的專案計畫,目前的最新版 (版本號 0.7.0) 已於 2022 年 7 月釋出。各位如有興趣貢獻一己之力開發軟體,非常歡迎前往 PyGMT 的官方網站一探究竟。 PyGMT is entirely a community-based project. Its latest version (0.7.0) was released in July 2022. If you are interested in contributing to and developing the project, I encourage you to go to the official website and forum of PyGMT and get involved. CC-BY-4.0 +我該使用 GMT 嗎? Should I use GMT? CC-BY-4.0 +如果你有製作地圖的需求,不管是全球地圖還是���家附近的街道圖,都可以考慮使用 GMT 或 PyGMT。不過,GMT 特別適合用於科學製圖,這是因為指令化的操作方式,讓觀測或實驗數據變得很容易搭配地理資訊一同呈現。因此,筆者尤其推薦給具有以下任一種需求的人: If you need to make some sort of map, either a global topography or a street map around your home, GMT or PyGMT has got you covered. With that said, GMT suits better for scientific mapping because all the data and observations can be easily processed by various built-in commands. Also, you can show your results with other GIS data but with no pain. Here I highly recommend GMT for people who want to perform any tasks listed below: CC-BY-4.0 +手邊有大量的地理數據需要呈現在地圖上。例如:降雨量分佈、斷層與地震帶、海底地形圖、全世界火山分佈圖等等。 **Show tons of data on a map**, like precipitation, faults and seismicity map, bathymetry, global volcano distribution, etc. CC-BY-4.0 +時常繪製地圖,並且總是覺得使用 GIS 軟體效率太低。學習指令列繪圖的技巧,一定能讓你的 GIS 繪圖效率大增。 **Make maps pretty often or update them frequently. You probably would feel that the fancy and clumsy graphic interface of GIS software always slows down your working efficiency**. Learning how to plot using command-line tools can improve your work and save lots of your time. CC-BY-4.0 +需要即時或互動性呈現地理資料分析的結果。執行 GMT 或 PyGMT 的腳本,可以讓你把資料分析和繪圖輸出這兩件事一次完成。 **Need to show the results of geospatial data analysis interactively or in real time.** You can get two jobs done at once -- data analysis and visualization -- by running a GMT or PyGMT script. CC-BY-4.0 +唯一的問題是,GMT 所有的功能都必須透過指令列操作,對於沒接觸過指令列程式的人而言,GMT 的上手曲線可能沒那麼平緩。幸好,GMT 自身的指令格式並不那麼困難,而且在大多數的情形下,我們也不需要使用 GMT 以外的指令操作資料,因此只要稍微熟稔一點操作介面的觀念,就可輕鬆上手。有關詳情可以參考「{doc}`basic_concept`」。另外,如果你使用過或正在使用 Python 程式語言,那麼可以嘗試看看模組化的 PyGMT,加速學習的效率。 The only issue with getting a swing of GMT is that you need to write a script consisting of some code (GMT commands) to get GMT to work. For those who never used a terminal console, a steep learning curve would be expected. Fortunately, the GMT built-in commands are not that hard compared to many other standard console commands, and in most cases, we do not need the non-GMT commands for manipulating data. That means as long as we have learned the basics of the command-line interface, we will be ready to master the art of GMT. Please go to {doc}`basic_concept` for more details. Besides, if you have used or are using Python programming language, you can just start with PyGMT to speed up your learning efficiency. CC-BY-4.0 +這本教學手冊 About the tutorials CC-BY-4.0 +[筆者](https://whyjz.github.io/)目前為地球物理與行星科學領域的研究員,接觸 GMT 已超過 10 年。有感於網路上缺少 GMT 與 PyGMT 的簡明教學資料,導致包括筆者在內的許多人得花額外的時間熟悉各種工具的用法,因此決定試著紀錄一些使用心得與操作程序,並設計成教學手冊,讓新手們可以由淺入深學習 GMT,老鳥們也可以把本教學當成工具書一般的查看。 [I](https://whyjz.github.io/) am a research scientist in geophysics and planetary sciences with more than 10 years of GMT experience. I always try hard to find well-organized and clear GMT tutorials, which sometimes makes me frustrated and spend more time learning every tool. So I decided to write down some of my scripts and thoughts and maybe write such a tutorial myself. My goal is to help beginners learn step-by-step by following the content of each chapter. If you are already a GMT veteran, I hope this tutorial can serve you as a reference book whenever you would like to look for answers to some specific questions. CC-BY-4.0 +本教學的難度,是放在讓從沒操作過指令列程式的使用者也能理解的等級,並循序漸進到一些比較像程式碼的華麗繪圖流程。學習 GMT 最佳的方法,除了參考本手冊或其他線上說明外,實際動手做更是掌握此工具的不二法門,因此在本教學中所有的章節都會提供繪圖資料以供各位使用,或許你可以畫得出比章節的目標更漂亮的地圖! Each chapter here is arranged in order by its difficulty. The first few chapters introduce basic knowledge for people who have zero experience of command lines. Later, the content shifts to some advanced script workflows. I believe the best way to learn GMT is to do it yourself rather than any online resources and these tutorials. With this in mind, you can find everything you need for making the map in each chapter, including the data and scripts. Feel free to download them and make a map that even surpasses the one I made! CC-BY-4.0 +如何安裝 How to install GMT CC-BY-4.0 +GMT 和 PyGMT 有許多種安裝方式,我個人推薦利用 `conda` 套件管理器安裝。至於其他的方法,可前往 [GMT](https://github.com/GenericMappingTools/gmt/blob/master/INSTALL.md) 或 [PyGMT](https://www.pygmt.org/latest/install.html) 的網站查看。 There are many ways to install GMT and PyGMT. I recommend using the `conda` package manager to install them. For other ways of installation, please go to the [GMT](https://github.com/GenericMappingTools/gmt/blob/master/INSTALL.md) or [PyGMT](https://www.pygmt.org/latest/install.html) official websites. CC-BY-4.0 +Anaconda 會預裝很多常用的 Python 套件。如果只想要 Conda 而不想要其他的套件,也可以選擇安裝 [Miniconda](https://docs.conda.io/projects/conda/en/latest/user-guide/install/download.html)。 Anaconda installs many highly-used Python packages. If you want to get Conda itself without having the other packages, you can choose to install [Miniconda](https://docs.conda.io/projects/conda/en/latest/user-guide/install/download.html). CC-BY-4.0 +首先[安裝 Anaconda](https://www.anaconda.com/products/individual)。Anaconda 是個跨平台的套件管理軟體,尤其適合資料科學分析使用。你可以根據你的作業系統下載不同的檔案安裝。安裝 Anaconda 時會一併安裝我們需要的 Conda 管理器。 Firstly you need to [install Anaconda](https://www.anaconda.com/products/individual). Anaconda is cross-platform package manager software for scientific data analysis. You can download the installation file based on your operating system and install Anaconda. The Conda package manager will be installed together with Anaconda. CC-BY-4.0 +開啟終端機 (Linux 或 Mac) 或是 Anaconda 的指令列 (Windows),使用具有第三方套件的 conda-forge 頻道做為安裝來源。更多關於終端機的詳細說明請看「{doc}`basic_concept`」。 Open the terminal (Linux or Mac) or Anaconda command window (Windows) and use the conda-forge channel (which contains third-party packages) as the installation source. For more details and explanations, please see {doc}`basic_concept`. CC-BY-4.0 +覺得 `conda` 太慢的話,可以裝 `mamba` 來加速安裝套件。請參閱 [Mamba 的說明文檔](https://mamba.readthedocs.io/en/latest/user_guide/mamba.html)以及 [PyGMT 的官方安裝示範](https://www.pygmt.org/latest/install.html)。 If `conda` is slow, you can install `mamba` to speed up the following package installation. Please see [Mamba's documentation](https://mamba.readthedocs.io/en/latest/user_guide/mamba.html) and [the guide from the official PyGMT site](https://www.pygmt.org/latest/install.html). CC-BY-4.0 +建立 GMT 的安裝環境並安裝 GMT。這邊環境的名字 `mygmt` 可自由更改成您喜歡的字。) Create a GMT environment and install GMT. Note you can change the environment name `mygmt` to any letter combination you like.) CC-BY-4.0 +或是你也可以直接安裝 PyGMT,這樣 GMT 會一併被安裝: Or you can install PyGMT directly as GMT will be installed as a dependency: CC-BY-4.0 +切換至 `mygmt` 環境即可開始使用 GMT/PyGMT。GMT 是在命令列介面 (Command-line interface, CLI) 下執行的工具,因此你可以在終端機中透過 `gmt` 這個指令使用 GMT 的所有功能。 Switch to the `mygmt` environment to start using GMT/PyGMT. GMT is a tool running in the command-line interface (CLI), and you can use the `gmt` command in the terminal to access GMT's full functionality. CC-BY-4.0 +如要使用 PyGMT,在 Python 互動介面或腳本內匯入同名模組即可: To start using PyGMT, import the `pygmt` module in the Python interface or a Python script: CC-BY-4.0 +"import pygmt +pygmt.show_versions()" "import pygmt +pygmt.show_versions()" CC-BY-4.0 +如果你計畫使用 PyGMT,推薦一併安裝 JupyterLab 以進行互動式資料分析。 If you plan to use PyGMT, I recommend installing JupyterLab as well for interactive data analysis. CC-BY-4.0 +使用者社群 User Community CC-BY-4.0 +GMT 與 PyGMT 有著日益茁壯的社群。[官方的使用者論壇 (英文)](https://forum.generic-mapping-tools.org/) 提供了使用者們交流、發問、參與開發的園地,也是軟體發布新版本時的公佈欄。 There is a growing GMT and PyGMT community. [The official GMT community forum](https://forum.generic-mapping-tools.org/) provides a space for users to interact, ask questions, and contribute to development. The forum also serves as the announcement board when a new software version is released. CC-BY-4.0 +Wessel, P., and Smith, W. H. F. (1991). Free software helps map and display data, EOS Trans. AGU, 72(41), 445–446. Wessel, P., and Smith, W. H. F. (1991). Free software helps map and display data, EOS Trans. AGU, 72(41), 445–446. CC-BY-4.0 +使用色階表為網格資料著色 Visualize Raster Data Using a Colormap CC-BY-4.0 +本教學適用於 GMT 6 的現代模式。 This instruction is for the Modern Mode in GMT 6. CC-BY-4.0 +在前幾章中,我們簡單介紹了地圖的著色技巧。本章將延續這個主題,介紹如何熟練的運用色階表,在地圖上任何你想要的地方著色。 We have introduced the basic skills to fill your map with colors in the previous chapters. Now we are going to continue this topic and show how to paint anywhere you like on a map using a colormap. CC-BY-4.0 +使用美國國家太空總署 (NASA) 提供的 ITS_LIVE 的資料集\\ [#]_\\ 與美國國家冰雪數據中心 (NSIDC) 提供的 GLIMS 冰河覆蓋區域資料\\ [#]_,繪製冰島上所有冰河的移動速度。為了方便判讀冰河移動速度,在地圖下方加上了色階條顯示速度與顏色的對應關係。圖中特別標記了冰島最大的冰帽:\\ `瓦特納冰原 `_ (Vatnajökull)。全冰島移動速度最快的冰河就發源於此冰帽,每年移動超過 400 公尺。沒有數據的冰河區域,會以灰色呈現在地圖上。 Using the ITS_LIVE dataset [#]_ provided by the National Aeronautics and Space Administration (NASA) and the GLIMS glacier outline dataset [#]_ provided by the National Snow and Ice Data Center (NSIDC), plot the glacier speed of all the glaciers in Iceland. To easily read the glacier speed, we also need to add a colorbar in the bottom showing the relationship between different colors and speeds. The largest ice cap in the island, `Vatnajökull `_, is also labeled on the map. The fastest glacier in Iceland flows from this ice cap with a speed of more than 400 meters per year. The glacierized areas without speed data are shown in gray on the map. CC-BY-4.0 +``coast`` - 繪製海岸線與陸海域填色 ``coast`` - plot shorelines and fill land/sea area CC-BY-4.0 +``clip`` - **只在給定的多邊形區域內繪製資料** ``clip`` - **only plot data within given polygon regions** CC-BY-4.0 +``makecpt`` - **製作與修改色階表** ``makecpt`` - **Make and adjust a color palette table** CC-BY-4.0 +``grdimage`` - 繪製著色影像 ``grdimage`` - plot colored image CC-BY-4.0 +``plot`` - 繪製多邊形 ``plot`` - **plot polygons** CC-BY-4.0 +``colorbar`` - 繪製色階條 ``colorbar`` - plot color bar CC-BY-4.0 +``text`` - 在圖上標記文字 ``text`` - Make text labels in a map CC-BY-4.0 +GMT 共用選項:``--長指令`` GMT shared options: ``--long command`` CC-BY-4.0 +外部指令 ``gdalwarp`` - **把網格資料重投影,並轉檔成 NetCDF 格式** External command ``gdalwarp`` - **reproject a raster file and convert it to NetCDF format** CC-BY-4.0 +如何解釋色階表 (CPT, color palette table) 的內容 How to read the content in a color palette table (CPT) CC-BY-4.0 +我們這次要使用兩種不同的額外資料,第一是冰河的移動速度,第二是冰河的覆蓋範圍。拜科技發展所賜,這兩種資料都可以在網路上免費取得。 We will use two different external datasets: the glacier speeds and the glacier outlines. Thanks to the development of technology, we can get both datasets free online. CC-BY-4.0 +首先來尋找冰河速度的資料吧。NASA 的 ITS_LIVE 計畫 (全名為「多種衛星組合成的陸冰速度與高度的時間序列」,Inter-mission Time Series of Land Ice Velocity and Elevation) 提供了多年份的冰河速度資料\\ [#]_。前往 `ITS_LIVE 的資料搜尋網頁 `_,在世界地圖上點選冰島的區域,會跳出一個白色的小視窗,如下圖所示。 First, let's take a loot at glacier speeds. NASA's ITS_LIVE (Inter-mission Time Series of Land Ice Velocity and Elevation) project provides multi-year time series of glacier speeds worldwide [#]_. Go to `ITS_LIVE data search page `_ and click on the region of Iceland, a small white sub-window will jump out like this: CC-BY-4.0 +點選藍色的區塊,選擇「Composite: 240m」(多年份彙整資料,240 米解析度) 的資料集,最後再點選「v」(速度) 的連結,下載 ``ICE_G0240_0000_v.tif``。這是一個 `GeoTIFF `_ 檔,也是一種網格地理資料儲存的格式,與 GMT 支援的 NetCDF 格式類似。不同的是,GeoTIFF 大多使用 ``.tif`` 作為副檔名,而且自身帶有網格的投影法與座標系統等資料。本檔案使用的投影法是 NSIDC 極區投影。為了讓 GMT 能夠正確讀取本檔案,我們需要使用 `GDAL `_ 附的 ``gdalwarp`` 指令,把 Geotiff 轉檔為 NetCDF 格式,並且重投影成經緯度編碼 (EPSG:4326): "Click the blue button and select the dataset of ""Composite: 240m"" (Multi-year composite data, 240-m posting). Finally, click the link at ""v"" (velocity) and download ``ICE_G0240_0000_v.tif``. This is a `GeoTIFF `_ file, a format also used for storing gridded rasters, which is similar to the NetCDF format that GMT supports. However, GeoTIFF files use ``.tif`` as their file extension and have additional metadata such as the grid projection and the coordinate system information. This raster used the NSIDC polar stereographic projection. In order to let GMT read the file correctly, we need to use ``gdalwarp``, a command of `GDAL `_ library, for converting Geotiff to NetCDF and reprojecting the file to lat/lon format (EPSG:4326):" CC-BY-4.0 +"$ gdalwarp -t_srs EPSG:4326 -dstnodata NaN -of NetCDF ICE_G0240_0000_v.tif ICE_G0240_0000_v_EPSG4326.nc +# 選項意義: +# -t_srs: 輸出檔案的投影法 (EPSG 是投影法的編碼系統。EPSG:4326 就是 WGS84 經緯度座標系統的編碼代號。) +# -dstnodata: 輸出檔案中代表「無資料」的數值 (NaN 意味著使用浮點數的 NaN 數值) +# -of: 輸出檔案格式" "$ gdalwarp -t_srs EPSG:4326 -dstnodata NaN -of NetCDF ICE_G0240_0000_v.tif ICE_G0240_0000_v_EPSG4326.nc +# Meaning of the options: +# -t_srs: the projection of the output file (EPSG represents numbered code for projection. EPSG:4326 is exactly WGS84 lat/lon system.) +# -dstnodata: the output file will use this value as no-data (NaN means to use the float-point number of ""NaN"" value) +# -of: output file format" CC-BY-4.0 +注意我們使用了不同的副檔名 ``.nc`` 代表這是 NetCDF 格式的網格檔。 Note that we use a different file extension ``.nc`` indicating a NetCDF-format raster file. CC-BY-4.0 +雖然這邊你可以使用任何你想得到的附檔名,但為了方便識別,我只推薦使用 ``.nc`` 或者\\ `之前提及到 `_\\ 的 ``.grd`` 作為 NetCDF 檔的副檔名。 You can use anything you want for the file extension here. Still, for better identification, I only recommend using ``.nc`` or ``.grd`` (`as we mentioned before `_) for the file extension of a NetCDF file. CC-BY-4.0 +再來我們要下載冰河覆蓋區域的資料。NSIDC 的 GLIMS 資料庫 (全名為「從太空測量全球陸冰」,Global Land Ice Measurements from Space) 具有全球冰河的資料\\ [#]_,但我們只需要冰島的區域就可以了。前往 `GLIMS Glacier Viewer `_,把地圖滑到冰島周圍,你應該會看到下圖: Now we are going to download another dataset, the glacier outlines. The GLIMS database (Global Land Ice Measurements from Space) of NSIDC provides global glacier data [#]_, but here we only need the data of Iceland. Go to `GLIMS Glacier Viewer `_ and slide the view to Iceland. You should see something like this: CC-BY-4.0 +點選「Download GLIMS Data in Current View」,然後在新開啟的視窗中的 File format 選單中選擇 GMT 格式,其他選項保持預設,最後按下 Download Data 按鈕。把下載的檔案解壓縮,裡面的 ``glims_polygons.gmt`` 檔案就是我們要的冰河覆蓋區域的多邊形檔。把它改名為 ``glims_iceland_glacier_outlines.gmt`` 以茲識別。 "Click ""Download GLIMS Data in Current View."" In the newly opened window, locate the ""File format"" menu and select GMT format, and leave other options as default. Finally, click the ""Download Data"" button. Extract the downloaded file and locate the ``glims_polygons.gmt``; this one is the polygon data of the glacier outlines, which we will use in this chapter. Rename it to ``glims_iceland_glacier_outlines.gmt`` for better identification." CC-BY-4.0 +這個 ``.gmt`` 檔其實是純文字檔,可以使用文字編輯器開啟。此格式將在「\\ :doc:`plot_vector_data`\\ 」中詳細描述與解釋。 This ``.gmt`` file is actually a text file, which can be opened by a text editor. We will explain this format in detail in :doc:`plot_vector_data`. CC-BY-4.0 +為了方便起見,你也可以直接從以下連結取得本章節使用的兩個檔案: For your convenience, you can also download the files used in this chapter from the links below: CC-BY-4.0 +首先我們使用 ``basemap`` 指定邊框、作圖區域與版面尺寸等等的設定;這裡我們要順便介紹一個新的指定地圖區域的方法。在之前的章節中,``-R`` 選項通常是以 ``西/東/南/北`` 邊界的座標指定。不過,當繪圖區域只涵蓋一個國家時,我們也可以簡單的使用國家的二位字母代碼 (請見\\ :doc:`pen_and_painting`\\ ),再加上 ``+R`` 調整地圖邊框與國家邊界的距離。因此,我們的 ``basemap`` 指令就變為: Firstly we use ``basemap`` for specifying map frame, map extent, size, etc. Here we are introducing a new way to assign map extent. In the previous chapter, ``-R`` option is usually given as ``W/E/S/N`` border coordinates. However, if the map fits a country, then we can simply use the 2-character code of that country (see :doc:`pen_and_painting`), with ``+R`` for adjusting the distance between the map frame and the country border. Thus, our ``basemap`` command becomes: CC-BY-4.0 +"gmt basemap -Baf -BWNEs -RIS+R0.2 -JM15c +# -RIS+R0.2: 以冰島 (IS) 作為地圖區域,冰島國界與地圖四周邊框保有 0.2 度的距離" "gmt basemap -Baf -BWNEs -RIS+R0.2 -JM15c +# -RIS+R0.2: use Iceland (IS) as the map extent. The distance between the national border of Iceland and the map frame is 0.2 degrees" CC-BY-4.0 +接下來我們就來綜合前幾個章節學到的指令以及相關選項,把冰島的海岸線畫出來: Now we can review the commands and options we learned from the previous chapters and plot the coastline of Iceland: CC-BY-4.0 +地圖下方沒有顯示經緯度座標,是預留給色階條的空間。 The coordinates are not showing at the bottom of the map, which is reserved for the color bar. CC-BY-4.0 +我們的下一步就是要把冰河速度畫上去,不過得先決定一個合適的色階才行。在之前繪製地形的例子中,我們使用了 GMT 本身提供,為地形資料設計的色階,而在本例中,由於沒有任何一個色階是設計用來表示冰河速度的,因此我們得自行設計才行。在 GMT 中設計色階的步驟為 Our next step is to plot the glacier speeds, but before this we need to determine a good color map. In the previous examples, we used the built-in colormap designed for topographical data. Since no colormaps are intentionally designed for representing glacier speeds, we need to design it ourselves. The steps to do this using GMT are CC-BY-4.0 +決定母色階 (預先定義好的顏色組合,但是對應的數值範圍尚未決定) 或是挑選數種顏色自行製作母色階 Choose a master colormap (pre-defined combination of colors without the corresponding value range), or choose several colors and make your own master colormap CC-BY-4.0 +使用 ``makecpt`` 或是 ``grd2cpt`` 決定色階對應的數值範圍以及前景、背景色等等資訊 Use ``makecpt`` or ``grd2cpt`` for specifying what color corresponds to what value, and also information like background color, foreground color, etc. CC-BY-4.0 +使用 ``grdimage`` 或是其他接受色階檔的指令畫上你的資料 Use ``grdimage`` or other commands requiring a colormap to plot your data CC-BY-4.0 +在本章中,我們會介紹最簡單的方法,也就是決定母色階之後,使用 ``makecpt`` 製作地圖要用的色階。如需參閱進階的技巧,請至\\ :doc:`editing_cpt_colorbar`。 In this chapter, we will introduce the easiest way, which is picking up a master colomap and then using ``makecpt`` to make a colormap for your map. For advanced skills, please go to :doc:`editing_cpt_colorbar`. CC-BY-4.0 +GMT 支援的所有母色階列表可以在\\ `官方說明頁面 `_\\ 中查詢。我在本章節中使用的是 batlow 色階,如下圖所示。你也可以自由選擇其他喜歡的色階代替。 "The complete list of master colormaps GMT supports can be found at the `official manual page `_. Here I am using the ""batlow"" colormap, as shown in this figure. You can also choose other colormap you like to replace it." CC-BY-4.0 +接下來我們要決定對應的數值範圍。你可以使用 GIS 軟體開啟 ``ICE_G0240_0000_v_EPSG4326.nc`` 並查看數值的分佈,或是使用 ``grdinfo`` 或 GDAL 的 ``gdalinfo`` 等指令在指令列中查看最大最小值。為了方便起見,我在這裡提供了一個合理的範圍:``0`` 至 ``400``。本網格檔的數值單位是 m/yr (公尺/年)。決定好色階檔和範圍後,就可以使用 ``makecpt`` 指令。它的基本語法為 Now we are going to decide the value range. You can use GIS software to open ``ICE_G0240_0000_v_EPSG4326.nc`` and check the histogram of pixel values, or you can use ``grdinfo`` or GDAL's ``gdalinfo`` and look up the maximum and minimum values in the terminal. For your convenience, I have provided a reasonable range here: ``0`` to ``400``. The unit of this raster file is m/yr (meters per year). After deciding the master colormap and the value range, we can now use the ``makecpt`` command. Its basic syntax is CC-BY-4.0 +gmt makecpt -C母色階檔名 [-T最小值/最大值/間距] [-Z] gmt makecpt -Cparent_cpt [-Tmin/max/spacing] [-Z] CC-BY-4.0 +只有 ``-C`` 是必要選項,但 ``-T`` 也是是讓我們指定範圍的重要選項。最小值與最大值指定色階對應的數值範圍,而間距意味著程式每隔多少數值就會對母色階取樣。我們來試著在終端機中輸入以下指令: ``-C`` is the only required option, but ``-T`` is also very important since it is used to specify the value range. You have to enter the minimum and the maximum number of your range (that will correspond to the colormap), and spacing means the interval to sample the color from the master colormap. Let us try to type the following command in the terminal: CC-BY-4.0 +輸入完指令後,螢幕上就會顯示這個色階表的設定: Press enter and you will see the details of this new colormap: CC-BY-4.0 +色階表的主要部份由 4 欄資料所構成。第 1 欄與第 3 欄是數值區段,而第 2 欄與第 4 欄為這個數值區段對應的 RGB 值顏色。以第一行為例,這個色階表說明在 ``0`` 至 ``100`` 間都使用 ``15/58.875/95`` 這個顏色。 The main part of this colormap is composed of 4 columns of data. The first and the third column are the value range, and the second and the fourth column are the RGB color values for this range. Take the first line, for example, this colormap says it uses this color ``15/58.875/95`` for any value between ``0`` and ``100``. CC-BY-4.0 +在間距為 ``100`` 的情況下,本色階表只有 4 個顏色區段。 When the spacing is set to ``100``, this colormap would only have 4 color segments. CC-BY-4.0 +色階表的最後三行 (``B``, ``F``, ``N``) 對應以下三種特殊情況: The last three lines of the colormap (``B``, ``F``, ``N``) are for the following three special situations: CC-BY-4.0 +``B`` 是指當數值低於色階表中的最小值時,所呈現的顏色。 ``B`` represents the color used for any value lower than the minimum value of the range. CC-BY-4.0 +``F`` 是指當數值高於色階表中的最大值時,所呈現的顏色。 ``F`` represents the color used for any value higher than the maximum value of the range. CC-BY-4.0 +``N`` 是指當數值為 NaN (無資料) 時,所呈現的顏色。 ``N`` represents the color used for NaN (no-data value). CC-BY-4.0 +如果加上 ``-Z`` 選項的話,就可以把離散的色階變成連續的色階 (在兩個取樣點之間,顏色會隨著數值變化。如果不加的話,兩個取樣點之間的任意數值顏色皆相同): If we add the ``-Z`` option, then we will be creating a continuous colormap (color varies between two sample points) instead of a discrete colormap (same color between two sample points): CC-BY-4.0 +你會發現第 2 欄與第 4 欄的顏色值現在不一樣了。以第一行為例,如果數值介於 ``0`` 與 ``100`` 之間,GMT 會以線性內插的方式找到對應的顏色。 You can notice that the color in columns 2 and 4 are now different from each other. Take the first line, for example: if the pixel value is between ``0`` and ``100``, GMT would find the corresponding color by linear interpolation. CC-BY-4.0 +在此腳本中,``makecpt`` 以如下的方式設定: In this script, we will set ``makecpt`` as follows: CC-BY-4.0 +"gmt makecpt -Cbatlow -T0/400/10 -D -Z -M --COLOR_NAN=gray +# -C: 母色階檔名 (batlow) +# -T: 對應數值範圍 (0 至 400 中每隔 10 對母色階取樣) +# -D: 使用色階的端點顏色當作前景與背景色 (修改 B 與 F 的設定;任何大於 400 的數值都會與 400 有著相同顏色;任何小於 0 的數值都會與 0 有著相同顏色) +# -Z: 使用連續色階 +# -M: 使用 GMT 預設的 NaN 顏色當作無資料點的顏色 (修改原本 N 的設定) +# --COLOR_NAN: 指定 GMT 預設的 NaN 顏色 (詳見後述)" "gmt makecpt -Cbatlow -T0/400/10 -D -Z -M --COLOR_NAN=gray +# -C: master colormap name (batlow) +# -T: corresponding range (0 to 400; sample a color from the master colormap using an interval of 10) +# -D: using the end-member colors for background and foreground colors (This will change the settings of B and F; any number higher than 400 will have the same color as 400; any number lower than 0 will have the same color as 0.) +# -Z: making a continuous colormap +# -M: using the default NaN color in GMT as the NaN color for the colormap (This will change the setting of N.) +# --COLOR_NAN: specifying the default NaN color in GMT (To be explained later)" CC-BY-4.0 +我們在指令中使用了 ``--COLOR_NAN`` 這個選項。它是所謂的「\\ **長指令**\\ 」,語法上與 -R、-Z 等等的「短指令」不同,要用如下的語法設定: "Here we used the option ``--COLOR_NAN``. This kind of option is called ""**long command**, which is different from -R or -Z, etc. (short commands) in terms of syntax. We have to use the following syntax for a long command:" CC-BY-4.0 +搭配 ``-M`` 和 ``--COLOR_NAN``,我們可以自由的更改數值為 NaN 時顯示的顏色。 Combining ``-M`` and ``--COLOR_NAN``, we can freely change the color for NaN values. CC-BY-4.0 +所有的 GMT 預設參數都可以使用「長指令」設定,參數列表可以透過以下的指令查詢: All of the GMT default parameters can be reset using long commands. You can view the full list of these parameters by entering the following command: CC-BY-4.0 +如需更多詳情,請參閱\\ :doc:`layout_design`。 For details, please go to :doc:`layout_design`. CC-BY-4.0 +在 GMT 6 (現代模式) 中下達 ``makecpt`` 後,色階的相關資訊會被保存在一個暫存檔中。當你接下來在腳本中使用 ``grdimage`` 等指令繪圖時,就可以不用附上 ``-C`` 指令和任何色階檔檔名,GMT 就會自動的讀取並套用這個暫存色階檔在網格擋上。 In GMT 6 (Modern mode), the colormap information will be saved in a temporary file after you run ``makecpt``. Thus, when you use ``grdimage`` later in your script to plot something, you don't need to include ``-C`` option and any colormap map; GMT would automatically read this temporary file and apply the newly created colormap to the grid file. CC-BY-4.0 +在 GMT 6 的傳統模式以及 GMT 5 以降的版本中,你需要使用重導向指令 ``>`` 把輸出的色階另存到一個檔案中,才能在後續的指令中使用。詳請請\\ `參閱這裡 `_。 In GMT 6 (Classic mode) and the older versions of GMT, you have to use the redirecting character ``>`` for saving the new colormap as a file, and then you can use the file for the following commands. `See this page for details `_. CC-BY-4.0 +現在我們馬上來使用 ``grdimage`` 畫畫看冰河速度: Now we can try to plot glacier speeds using ``grdimage``: CC-BY-4.0 +等等...冰島的輪廓整個不見了!與之前的那張地圖比對一下,看來是因為 ``ICE_G0240_0000_v_EPSG4326.nc`` 中含有廣大範圍的 NaN 資料點,因此地圖的大部分區域都被灰色蓋住了。如果我們只是移動 ``coast`` 指令到 ``grdimage`` 後方,企圖再次劃上海岸線,就會發現這其實是沒有用的,``coast`` 的填色會蓋掉所有 ``grdimage`` 的輸出。那麼,要如何保有 ``coast`` 的填色並且讓冰河的速度一併顯示在圖上呢?這時候就要派 ``clip`` 指令上場了。``clip`` 指令的用法為 Wait a second... the outline of Iceland is gone! Take a look at the difference from the previous map, and you'll know this is because ``ICE_G0240_0000_v_EPSG4326.nc`` has lots of NaN points, so a vast area on the map is covered by gray. We can try to just move the ``coast`` command to the next line of ``grdimage`` for plotting the coastline again, but this does not help the situation because the filling of ``coast`` command would cover all output from ``grdimage``. How to keep the land filling from ``coast`` while plotting the glacier speeds on the map? Now we have to use the ``clip`` command. Here's how to use the ``clip`` command: CC-BY-4.0 +"gmt clip 作圖範圍檔案 +gmt grdimage ... +gmt clip -C" "gmt clip extent_file +gmt grdimage ... +gmt clip -C" CC-BY-4.0 +``作圖範圍檔案`` 必須要是以純文字格式記載的多邊形向量檔。相關的格式描述,我們將在「\\ :doc:`plot_vector_data`\\ 」中介紹。我們稍早之前下載的 ``glims_iceland_glacier_outlines.gmt`` 就是一個此類型的檔案。所有包夾在兩個 ``clip`` 指令內的作圖指令,都只會畫在被作圖範圍檔案定義的多邊形內。如果我們使用的是冰河範圍,那麼 GMT 就只會在冰河的覆蓋範圍內畫上冰河速度,這樣一來可以大大的減少 NaN 的灰色面積。把這段指令修改到我們的腳本中: The ``extent_file`` has to be an ascii-fromat vector (shape)file containing polygons. We will describe more about this kind of file more in :doc:`plot_vector_data`. The ``glims_iceland_glacier_outlines.gmt`` that we downloaded earlier exactly follows this format. All commands in between two ``clip`` commands will only be effective within the polygons defined by the extent file. If we use the glacier outlines here, then GMT will only plot glacier speeds within these outlines. Thus, the gray areas of NaN will be largely reduced. Apply this command segment to our script: CC-BY-4.0 +"speed_file=ICE_G0240_0000_v_EPSG4326.nc +glacier_outline=glims_iceland_glacier_outlines.gmt + +gmt begin iceland_glacier_speed png + gmt basemap -Baf -BWNEs -RIS+R0.2 -JM15c + gmt coast -Wthinnest,darkred -Gdarkseagreen1 -Slightblue -A1 + # 裁剪路徑開始 + gmt clip $glacier_outline + gmt makecpt -Cbatlow -T0/400/10 -D -Z -M --COLOR_NAN=gray + gmt grdimage $speed_file + gmt clip -C + # 裁剪路徑結束 +gmt end" "speed_file=ICE_G0240_0000_v_EPSG4326.nc +glacier_outline=glims_iceland_glacier_outlines.gmt + +gmt begin iceland_glacier_speed png + gmt basemap -Baf -BWNEs -RIS+R0.2 -JM15c + gmt coast -Wthinnest,darkred -Gdarkseagreen1 -Slightblue -A1 + # path clipping begins + gmt clip $glacier_outline + gmt makecpt -Cbatlow -T0/400/10 -D -Z -M --COLOR_NAN=gray + gmt grdimage $speed_file + gmt clip -C + # path clipping ends here +gmt end" CC-BY-4.0 +這樣總算是達到我們的目標。注意在圖上仍然有些灰色區域,不過這是因為冰河速度資料本來就不是百分之百涵蓋所有冰河覆蓋區域的緣故,因此予以保留。 Finally, our goal has achieved. Note that there are still some gray patches on the map, but this is completely normal since the data of glacier speeds do not cover 100% of the glacier extent. We can just keep them. CC-BY-4.0 +在地圖製作的最後幾個步驟,我們要複習前幾章學到的指令與技巧,加上冰河輪廓 (``plot``)、色階條 (``colorbar``),以及 Vatnajökull 的標記 (``text``)。下方快速的列出使用的選項與它們的意義,如需更詳細的說明,請至\\ :doc:`pen_and_painting`\\ 及\\ :doc:`scatter_plot` 章節中查詢。 For the last few steps of map making, we are going to review the commands and skills we picked up from the previous chapters. Here we will add the glacier outlines (``plot``), colorbar (``colorbar``), and the label showing the location of Vatnajökull (``text``). The following code simply lists some options used and their meanings. If you need a more detailed explanation, please go to :doc:`pen_and_painting` and :doc:`scatter_plot`. CC-BY-4.0 +"gmt plot $glacier_outline -Wthinner,black +# -W: 輪廓使用黑色細線 +gmt colorbar -DJCB+w6c+ef -Bx100+l""Glacier Speed (m/yr)"" +# -DJ: 把色階圖例畫在地圖外部的九宮格錨點中的任一個位置。下方置中 (CB),長度 6 公分 (+w6c), +# 在色階的最大值處劃上三角形,表示有數值超出顏色表示的最大值 (+ef) +# -B: 座標軸刻度間距為 100 (x100),在下方列出色階的意義及單位 (+l""Glacier Speed (m/yr)"") +echo -16.8 64.95 Vatnajökull | gmt text -F+f12p+jCM +# -F: 字體大小 12 點 (+f12p),垂直水平置中對齊給定的座標 (+jCM)" "gmt plot $glacier_outline -Wthinner,black +# -W: uses black thin lines +gmt colorbar -DJCB+w6c+ef -Bx100+l""Glacier Speed (m/yr)"" +# -DJ: plot the colorbar at one of the 2-character positions (CB - bottom centered) OUTSIDE the map. 6 cm wide (+w6c), +# plot a triangle at the maximum value indicating that there are values higher than this (+ef) +# -B: tick interval set to 100 (x100), the meaning and the unit of the colormap shown at the bottom (+l""Glacier Speed (m/yr)"") +echo -16.8 64.95 Vatnajökull | gmt text -F+f12p+jCM +# -F: font size set to 12 points (+f12p), vertically and horizontally center-aligned to the given coordinates (+jCM)" CC-BY-4.0 +"# ==== 設定輸入檔 ==== +speed_file=ICE_G0240_0000_v_EPSG4326.nc +glacier_outline=glims_iceland_glacier_outlines.gmt + +# ==== 主要指令 ==== +gmt begin iceland_glacier_speed png + gmt basemap -Baf -BWNEs -RIS+R0.2 -JM15c # 底圖 + gmt coast -Wthinnest,darkred -Gdarkseagreen1 -Slightblue -A1 # 海岸線與填色 + gmt clip $glacier_outline # 開始使用多邊形裁剪路徑 + gmt makecpt -Cbatlow -T0/400/10 -D -Z -M --COLOR_NAN=gray # 製作本地圖使用的色階 + gmt grdimage $speed_file # 在多邊形內繪製冰河速度 + gmt clip -C # 結束使用多邊形裁剪路徑 + gmt plot $glacier_outline -Wthinner,black # 冰河覆蓋範圍 + gmt colorbar -DJCB+w6c+ef -Bx100+l""Glacier Speed (m/yr)"" # 色階條 + echo -16.8 64.95 Vatnajökull | gmt text -F+f12p+jCM # 文字標記 +gmt end" "# ==== Setting input files ==== +speed_file=ICE_G0240_0000_v_EPSG4326.nc +glacier_outline=glims_iceland_glacier_outlines.gmt + +# ==== Main commands ==== +gmt begin iceland_glacier_speed png + gmt basemap -Baf -BWNEs -RIS+R0.2 -JM15c # basemap + gmt coast -Wthinnest,darkred -Gdarkseagreen1 -Slightblue -A1 # coastline and filling + gmt clip $glacier_outline # polygon path clipping begins + gmt makecpt -Cbatlow -T0/400/10 -D -Z -M --COLOR_NAN=gray # making the colormap used in this map + gmt grdimage $speed_file # plot glacier speed within the polygons + gmt clip -C # polygon path clippling ends + gmt plot $glacier_outline -Wthinner,black # glacier outlines + gmt colorbar -DJCB+w6c+ef -Bx100+l""Glacier Speed (m/yr)"" # colorbar + echo -16.8 64.95 Vatnajökull | gmt text -F+f12p+jCM # text label +gmt end" CC-BY-4.0 +「繪製冰島的冰河速度地圖:以冰島國家邊界加減 0.2 度為邊界,使用 ``batlow`` 當作冰河速度的\\ **母色階**\\ ,重新在 **0** 到 **400** 中取樣,製作\\ **連續色階**\\ ,無資料的地方以\\ **灰色**\\ 表示。冰河速度只會畫在由 ``glims_iceland_glacier_outlines.gmt`` 定義的冰河範圍內。最後畫上冰河覆蓋範圍、色階條以及標記 Vatnajökull 的位置。」 """Make a map showing glacier speeds in Iceland. Use Iceland's country border plus-minus 0.2 degree as the map extent. Use ``batlow`` as the **master colormap** of glacier speeds, and relate it to a range of **0** to **400**. We sample colors from the master colormap and make a **continuous colormap**. **Gray** represents areas with no data. Glacier speeds will be only plotted within the glacier outlines defined by ``glims_iceland_glacier_outlines.gmt``. Lastly, we plot the glacier outlines, a colorbar, and a label showing the location of Vatnajökull.""" CC-BY-4.0 +使用 ``dem4`` 這個母色階,繪製冰島的地形圖,並附上色階條。 Using ``dem4`` as the master colormap, make a topographical map of Iceland. Attach the colorbar. CC-BY-4.0 +使用你喜歡的色階,再次繪製冰島的地形圖,但是這次在所有冰河覆蓋的區域,無視其高度,一律塗上藍色。 Plot the topography of Iceland again using any colormap you like, but this time try to fill all glacier-covered area with blue. CC-BY-4.0 +畫筆與調色技巧 Pen and Painting CC-BY-4.0 +本教學適用於 GMT 6 的現代模式。如須參閱 GMT 6 (傳統模式) 與 GMT 4-5 繪製相似地圖的教程,\\ `請至這裡 `_。 This instruction is for the Modern Mode in GMT 6. For making the same map using the GMT 6 Classic Mode or GMT 4-5, `Please go to this page `_ (only final script and partial instruction). CC-BY-4.0 +為了有效的在地圖上呈現資料,顏色與線條樣式應要謹慎選擇。為地圖挑選合適的配色是門藝術,地圖製作者通常都會花上許多時間,把地圖調整成看起來最調和、最舒服的外觀。這裡我們要介紹如何在 GMT 中操作相關設定,讓你能夠更快的找到心目中的完美配色。本章也會說明如何繪製簡單的色階圖例。 In order to show the data on a map effectively, we should select all the colors and line styles with discretion. Picking the right color and line combination for a map is truly an art - a map maker usually spends much time tweaking their map, and hopes that their map will look pleasing and comfortable. Here we are going to introduce how to manipulate the related settings in GMT, which will make you find your best combination for your map must faster. We will also show how to make a simple colorbar legend on the map in this chapter. CC-BY-4.0 +製作一張中美洲的地圖,海域部份為分層設色地形圖,陸域部份則依國家來著色,如下圖所示。被中美地峽與島嶼群圍起來的區域為\\ `加勒比海 `_,而左上方的海灣則為\\ `墨西哥灣 `_。圖中可以找到此區域的十幾個比較大的國家,也可以發現加勒比海和墨西哥灣,都比東北方的大西洋要淺得多。根據地圖上的海床色階圖例,也可以發現最深的地方位於波多黎各北方的海溝,有大概 8000 多公尺深。 Make a map of Central America. Ocean area is colored based on topography, and the Land area is colored based on countries, as the following map shows. The water area encircled by central America and many islands is `Caribbean Sea `_, and the bay area at the upper left corner is called the `Gulf of Mexico `_. On this map, you can quickly locate more than a dozen big countries (in terms of area) and realize that both the Caribbean Sea and the Gulf of Mexico are much shallower than the Atlantic Ocean in the northeast. According to the bathymetry depth colorbar legend, we can also find that the deepest place is in the north of Puerto Rico, at more than 8000 m deep. CC-BY-4.0 +``coast`` - **為國家上色** ``coast`` - **fill countries with colors** CC-BY-4.0 +``colorbar`` - **繪製色階條** ``colorbar`` - **plot color bar** CC-BY-4.0 +``grdinfo`` - 查閱網格檔的基本資訊 ``grdinfo`` - display basic information from a grid file CC-BY-4.0 +外部指令 ``grep`` - **在 GMT 的輸出中搜尋字串** (Windows 為 ``findstr``) (非必要) External command ``grep`` - **find strings in GMT output text** (``findstr`` in Windows) (optional) CC-BY-4.0 +如何指定作圖顏色 How to specify colors on a map CC-BY-4.0 +畫筆的屬性設定 Setting up pen attributes CC-BY-4.0 +疊加多個圖層 Overlay multiple map layers CC-BY-4.0 +在腳本中使用變數以美化排版 Use variables in a script to make your script look pretty CC-BY-4.0 +使用錨點指定色階條的繪製位置 Use anchor points to specify location to plot the colorbar CC-BY-4.0 +在本章中,我們一樣會使用 GMT 伺服器提供的 ``@earth_relief_01m`` 資料庫。相關的介紹請看「\\ :doc:`coloring_topography`\\ 」。本次的作圖區域,是 ``-R-100/1/-50/34r``,如以下 *Google Map* 截圖所示。有關 ``-R`` 的詳細說明,請參閱「\\ :doc:`making_first_map`\\ 」。 In this chapter, we will again use the ``@earth_relief_01m`` dataset from the GMT server. For more details, please see :doc:`coloring_topography`. The extent of the desired map is ``-R-100/1/-50/34r``, as the following *Google Maps* screenshot shows. Please see :doc:`making_first_map` for more details about ``-R``. CC-BY-4.0 +我們先來分析一下目標的地圖。在此地圖中有很多不同的元素,依照固定的順序疊加。如果認真檢查,這些元素可以分成四群,由底層到頂層分別為 Firstly let’s take a look at our desired map. There are many different elements overlaid with a fixed order in the map. We can generally classify them into four groups, which are (from the bottom to the top) CC-BY-4.0 +地形圖 Topography map CC-BY-4.0 +國家的著色 Country blocks CC-BY-4.0 +海岸線、國家邊界與地圖格線 Coastline, borders, and grid lines CC-BY-4.0 +色階圖例的區塊 The block for the colorbar legend CC-BY-4.0 +因此,我們的 GMT 繪圖腳本,應該也要照如上的順序進行繪圖,也就是說程式碼看起來會長這樣 Therefore, the commands in our GMT script should follow this order; i.e. your code will look like this: CC-BY-4.0 +"第一段:海底地形圖 (grdimage) +第二段:國家的著色 (coast) +第三段:所有的線段 (coast) +第四段:色階條 (colorbar)" "Section 1: bathymetry (grdimage) +Section 2: filling of the countries (coast) +Section 3: all lines (coast) +Section 4: color bar (colorbar)" CC-BY-4.0 +海底地形圖和國家著色,都必需要指定繪圖的顏色或色階,所以這裡我們先來看看單一的顏色要怎麼指定。最簡單,並也在之前的章節使用的一種方法,就是指定顏色的名稱。GMT 支援了超過百種顏色的名稱,可以在\\ `這邊 `_\\ 查看並使用。例如說以下指令 You will need to assign a color or a series of colors (color ramp) for both bathymetry and countries. First off, let’s see how to specify a single color. The simplest way, which has been used in the previous chapter, is providing the name of the desired color. GMT supports more than a hundred names of colors, and you can check them out at `here `_ and use them directly. For example, the following command CC-BY-4.0 +gmt coast -Ggreen # ...後續省略 gmt coast -Ggreen # ... the later part is skipped CC-BY-4.0 +可以把陸域染成綠色。由於這裡我們要著色的是個別的國家,所以得先介紹另外一個 ``coast`` 的選項 ``-E`` 才行。``-E`` 會讀取一個稱為 `DCW `_ 的資料庫,使用內含的國家邊界資料進行著色。``-E`` 的語法大致為 will fill the land with green. Since we are going to fill the country blocks, we have to use another ``coast`` option ``-E``. The ``-E`` option reads a database called `DCW `_ and fills the blocks using the political boundaries data found from the database. Its syntax is CC-BY-4.0 +'-E代碼1,代碼2,...+g填色+p畫筆' '-E(code1),(code2),...+g(fill)+p(pen)' CC-BY-4.0 +其中的\\ ``代碼``\\ 指的是 `ISO 3166-1 alpha-2 `_ 國家名稱的二位字母代碼,例如 ``TW`` 代表台灣,``US`` 代表美國等等。除了可以從維基百科查詢這些代碼以外,也可以輸入以下指令,直接在 GMT 中查詢: Here ``code`` represents the 2-letter code of country name from `ISO 3166-1 alpha-2 `_. For example, ``TW`` is Taiwan, and ``US`` represents the United States. Besides from checking the code table from the Wikipedia, you can also enter the following command and search them in GMT: CC-BY-4.0 +"$ gmt coast -E+l # 在螢幕中列出二位字母國碼 +# 或 +$ gmt coast -E+L # 在螢幕中列出二位字母國碼與幾個大國家的省份碼" "$ gmt coast -E+l # show the 2-letter national code on the screen +# or +$ gmt coast -E+L # show the 2-letter national and province code on the screen (only for big countries)" CC-BY-4.0 +這邊順便舉個方便的技巧:如果你想查詢特定國家 (已經知道英文國名) 的代碼,可以使用 ``sh`` 內建的 ``grep`` 指令來輔助查詢。如下這樣: There is a useful trick: if you want to search for a specific country (the name is know), you can use ``grep``, a built-in command in ``sh`` to assist the search, like this: CC-BY-4.0 +這邊的 ``-i`` 選項是「大小寫視為相同」之意。在下方的搜尋結果中,就出現了日本的代碼 ``JP``。 The ``-i`` option here is to treat upper-case letters the same as lower-case letters. You can see that Japan’s code ``JP`` appears in the last line. CC-BY-4.0 +如果你的作業系統是 **Windows**,內建會沒有 ``grep``,但你可以使用替代的指令 ``findstr`` 來操作,如下: If your system is **Windows**, ``grep`` is not available, but you can use an alternative command ``findstr`` for the same query. To use it: CC-BY-4.0 +如果你想要使用 ``grep`` 一次查詢多個國家,可以使用如下語法: If you want to use ``grep`` for querying more than one country at once, use the following syntax: CC-BY-4.0 +這樣程式會一次把日本、新加坡跟紐西蘭的代碼找出來。 And the command will find the code for Japan, Singapore, and New Zealand, all at once. CC-BY-4.0 +接下來就是\\ **填色**。GMT 實際上支援了六種顏色表達方式,分別為 And the next task is to fill **colors**. GMT supports six ways to represent colors: CC-BY-4.0 +"「green」 # 1. 使用顏色名稱 +「255/99/71」 # 2. 使用 R/G/B 值 (從 0 到 255),左邊這是蕃茄色 +「#87CEEE」 # 3. 使用 HTML 標��的顏色表示法 (#RRGGBB,十六進位),左邊這是天藍色 +「25-0.86-0.82」 # 4. 使用 H-S-V 值 (前者從 0 到 255,後兩者從 0 到 1),左邊這是巧克力色 +「8/8/0/2」 # 5. 使用 C/M/Y/K 值 (百分比表示),左邊這是薰衣草色 +「169」 # 6. 灰階號碼,此例相當於 R/G/B 的 169/169/169" """green"" # 1. Color name +""255/99/71"" # 2. R/G/B value (from 0 to 255). This is tomato color +""#87CEEE"" # 3. HTML color representation (#RRGGBB,hexadecimal). This is sky blue +""25-0.86-0.82"" # 4. H-S-V value (H from 0 to 255; S and V from 0 to 1). This is chocolate color +""8/8/0/2"" # 5. C/M/Y/K value (in percentage). This is lavender +""169"" # 6. Grayscale number. This one is equivalent to 169/169/169 in R/G/B" CC-BY-4.0 +你可以使用你喜歡的表達方式給定顏色。這邊我們要試著幫墨西哥 (代碼 ``MX``) 塗上磚紅色,使用 HTML 標記的代碼 ``#CD5C5C``,語法如下: You can use whichever way you like to specify colors. Here we try to fill Mexico (code ``MX``) with brick red using HTML code ``#CD5C5C`` as following: CC-BY-4.0 +$ gmt coast -R-100/1/-50/34r -JM15c -EMX+g#CD5C5C -png central_america # 地圖 15 公分寬 $ gmt coast -R-100/1/-50/34r -JM15c -EMX+g#CD5C5C -png central_america # the map is 15 cm wide CC-BY-4.0 +成品就會看到有個磚紅色的區塊,這就是墨西哥的國土。 In the output PNG, you can see that the land area of Mexico has turned into brick red. CC-BY-4.0 +因為我們等一下會為不同的國家塗上不同的顏色,為了程式碼的美觀,可以把顏色和對應的國家先以變數的方式存放,之後執行 ``coast`` 再使用這些變數。這種方式除了可以整齊排版,更利於之後的編輯修改。每個 shell 指定變數的方式略有不同,這裡以 ``bash`` 為示範,變數的指定與取方式為: Since we are going to use many different colors for different countries, we can specify those colors and the corresponding countries in variables and use them later when running ``coast``. This not only makes your code look clean and pretty, but also more convenient for later editing. The ways to assign variables are slightly different from shell to shell, and here we will use ``bash`` as an example. You can use the following expression to assign and access your variable: CC-BY-4.0 +"變數名稱='變數內容' # 指定變數 +${變數名稱} # 存取變數 (這串文字會被'變數內容'取代掉)" "variable_name='variable_content' # assigning a variable +${variable_name} # accessing a variable (""variable_name"" will be substituted by ""variable_content"")" CC-BY-4.0 +把上述語法套用到我們的例子中,就像是這樣: Use the syntax to our example and the code will look like: CC-BY-4.0 +以上腳本可以把墨西哥 (``MX``)、巴西 (``BR``)、巴拿馬 (``PA``) 和多明尼加 (``DO``) 一次塗上磚紅色。如果你想要更改顏色或國家,只要修改變數 ``colorgroup1`` 或 ``color1`` 的內容即可,不需要動到 ``coast`` 的指令。 This code snippet can paint Mexico (``MX``), Brazil (``BR``), Panama (``PA``), and Dominican (``DO``) with brick red at once. If you want to change the color or the country list, you only need to change the content of ``colorgroup1`` or ``color1`` and leave the ``coast`` command the same. CC-BY-4.0 +由於不同的指令列環境有不同的變數設定方式,而且是值得另闢章節討論的話題,在此我們先略過這些內容以集中精神在 GMT 指令上。有關於變數指定的細節,請參考你所使用的 shell 如 cmd、bash 或 csh 等的技術專書或網頁。 A different command-line environment has a different way to set up variables, and this is not an easy topic regarding which one you are using. Here we will only focus on the GMT commands. For the details of using variables, please refer to some websites or books designed for your shell, e.g., cmd, bash or csh. CC-BY-4.0 +有許多不錯的網頁調色盤,如 `HTML color codes `_,可以幫助你用視覺化的方式挑選你想要的顏色,然後再把色碼貼到腳本變數中就行了。好好尋找你想要的顏色吧! There are many online palettes, such as `HTML color codes `_, which helps you pick the color you want. After you decide the color from the website, you can simply copy the color code and paste it to the variables in the script. Have fun hunting for colors! CC-BY-4.0 +接下來,只要依樣畫葫蘆,把所有的鄰近國家都填上顏色就可以了。依照\\ `上一章 `_\\ 所示,我們先使用 ``grdimage`` 畫地形底圖,再使用 ``coast`` 把剛剛提的所有東西填上去: Next, we are going to use the same way to fill all the neighboring countries with color. As the `previous chapter `_ shows, we firstly use ``grdimage`` to plot bathymetry, and then use ``coast`` to fill everything on the map: CC-BY-4.0 +"# ==== 設定顏色與對應的國家 ==== +# mexico, brazil, costa rica, dominican +color1='#CD5C5C' +colorgroup1='MX,BR,CR,DO' +# guatemala, venezuela, jamaica, french guiana, bahamas +color2='pink' +colorgroup2='GT,JM,VE,GF,BS' +# united states, puerto rico, nicaragua, guyana +color3='240/230/140' +colorgroup3='US,PR,NI,GY' +# belize, haiti, trinidad and tobago, panama, salvador +color4='0/36/74/4' +colorgroup4='BZ,HT,TT,PA,SV' +# colombia, cuba, honduras, suriname +color5='97-0.52-0.94' +colorgroup5='CO,CU,HN,SR' +# 其他國家 +color0='169' + +# ==== 主要指令 ==== +gmt begin central_america png + gmt grdimage @earth_relief_01m -JB-80.27/8.58/-8/24/15c -R-100/1/-50/34r -Cgeo + gmt coast -G${color0} \\ + -E${colorgroup1}+g${color1} \\ + -E${colorgroup2}+g${color2} \\ + -E${colorgroup3}+g${color3} \\ + -E${colorgroup4}+g${color4} \\ + -E${colorgroup5}+g${color5} +gmt end" "# ==== Setting up colors and corresponding countries ==== +# mexico, brazil, costa rica, dominican +color1='#CD5C5C' +colorgroup1='MX,BR,CR,DO' +# guatemala, venezuela, jamaica, french guiana, bahamas +color2='pink' +colorgroup2='GT,JM,VE,GF,BS' +# united states, puerto rico, nicaragua, guyana +color3='240/230/140' +colorgroup3='US,PR,NI,GY' +# belize, haiti, trinidad and tobago, panama, salvador +color4='0/36/74/4' +colorgroup4='BZ,HT,TT,PA,SV' +# colombia, cuba, honduras, suriname +color5='97-0.52-0.94' +colorgroup5='CO,CU,HN,SR' +# 其他國家 +color0='169' + +# ==== Main commands ==== +gmt begin central_america png + gmt grdimage @earth_relief_01m -JB-80.27/8.58/-8/24/15c -R-100/1/-50/34r -Cgeo + gmt coast -G${color0} \\ + -E${colorgroup1}+g${color1} \\ + -E${colorgroup2}+g${color2} \\ + -E${colorgroup3}+g${color3} \\ + -E${colorgroup4}+g${color4} \\ + -E${colorgroup5}+g${color5} +gmt end" CC-BY-4.0 +注意在 ``grdimage`` 中,``-J`` 選項使用了 ``B``,這是另一種稱為 `Albers 投影 `_\\ 的地圖投影法,是一種圓錐型投影,可使地圖上的每個區域面積保持一致。它的語法為 Note that in ``grdimage``, we choose ``B`` for the ``-J`` option. This is a different map projection called `Albers Projection `_. Albers projection is a conic projection that keeps everywhere on the map staying in their original size. Its syntax goes like this: CC-BY-4.0 +'-JB投影中心經線/投影中心緯線/圓錐上端緯線/圓錐下端緯線/地圖尺寸' '-JB[center_lon]/[center_lat]/[upper_bond_lat]/[lower_bond_lat]/[map_width]' CC-BY-4.0 +另外,在「\\ :doc:`coloring_topography`\\ 」中也提過,地形資料的 ``-C`` 選項 (色階) 預設值是 ``geo``。這邊我們為了使讀者了解我們使用的設定,因此特地加上 ``-Cgeo``。實際上,就算不加上色階檔檔名 (``-C`` 或乾脆省略),GMT 也會使用相同的色階畫圖。在\\ ``設定顏色與對應的國家``\\ 的部份,我們總共指定了 6 種顏色與 22 個國家。``color0`` 是灰色,用於中美洲其餘的國家。而在\\ ``主要指令``\\ 中,我們先使用 ``-G`` 把所有陸域塗上灰色,然後再使用 ``-E`` 為各個國家填色。你會發現所有的 ``-E`` 選項都可以被加在同一個 ``coast`` 指令內,省去重複輸入的麻煩!整個腳本執行的結果如下所示 (中文註解可能要改成英文才可順利執行)。 As we mentioned in :doc:`coloring_topography`, the default ``-C`` setting (colormap) for topographic data is ``geo``. To help readers understand the settings used in the map, we use ``-Cgeo`` explicitly. In fact, GMT still uses the same colormap without adding ``geo``, or even without ``-C``. In the ``Setting up colors and corresponding countries`` section, we specify 6 colors and 22 countries. The gray ``color0`` is used for other countries in the map area. In the ``Main commands`` section, we firstly use ``-G`` to paint all land areas in gray, and then use ``-E`` for coloring each country. You may notice that all the ``-E`` options can be assigned in a single ``coast`` command, which saves your time from entering the ``coast`` command multiple times. Run the script, and you should get the output map like this: CC-BY-4.0 +接下來,我們再為國界和海岸線畫點線,國家就會更突顯出來。在\\ :doc:`making_first_map`\\ 中,我們曾經提及線條的「畫筆樣式」由三個部份組成:``粗細,顏色,樣式``。``粗細`` 可以為預先定義好的名稱,像是 ``thinner``、``thickest``,``fat``\\ 等等,總共有 12 個,所有的名稱可以在\\ `此連結 `_\\ 查詢。如果你想要自訂粗細,也可以使用 ``c`` (公分)、``i`` (英吋)、``p`` (點) 等長度單位,如 ``0.1c`` 就是 0.1 公分。畫筆的\\ ``顏色``\\ 與上述的色碼通用,選你喜歡的��達方式即可。畫筆的\\ ``樣式``\\ 預設是連續線條,你可以使用 ``-`` (折線) 與 ``.`` (點) 自由的混搭樣式,如 ``-..`` 會畫出折線中間間隔兩個點的線條。以下是一些示範: "The next thing is to draw coastlines and country borderlines so that these countries will jump out. In :doc:`making_first_map`, we mentioned that the ""pen attributes"" of a line consist of three parts: ``thickness,color,style``. ``thickness`` can be predefined names, such as ``thinner``, ``thickest``, or ``fat``. There are 12 names for thickness, and `you can check them up here `_. If you would like to specify thickness manually, you can use units like ``c`` (cm), ``i`` (inch), ``p`` (pt). For example, ``0.1c`` stands for 0.1 cm. The ``color`` of the pen uses the same color code system we said earlier in this chapter, so just use any expression you like. The ``style`` of the pen is a solid, continuous line, and you can freely combine ``-`` (dash) and ``.`` (dot) to generate the line style you want. For example, ``-..`` means a line with two dots lying in between two dashes. Here are more examples:" CC-BY-4.0 +"thinner,green,- # 綠色的細折線 (0.5 點) +3p,100/0/100,. # 3 點寬,深紫色的點線 +1c,#555555,--.. # 1 公分寬,灰色的 ""--.."" 樣式線條" "thinner,green,- # green, thin solid line (0.5 pt) +3p,100/0/100,. # deep purple dotted line in 3 pt wide +1c,#555555,--.. # gray, ""--.."" styled line in 1 cm wide" CC-BY-4.0 +``coast`` 有三個跟畫線有關的指令,分別為 ``coast`` has three options that plot lines. They are: CC-BY-4.0 +"'-I編號/畫筆 # 畫上河流 +-N編號/畫筆 # 畫上政治邊界 +-W編號/畫筆 # 畫上水域邊界'" "'-I[number]/[pen] # Draw rivers +-N[number]/[pen] # Draw political borders +-W[number]/[pen] # Draw shorelines'" CC-BY-4.0 +其中 ``-I`` 和 ``-N`` 的編號已在\\ :doc:`coloring_topography`\\ 中介紹過,而 ``-W`` 的編號可以為 ``1``、``2``、``3`` 及 ``4``,分別代表海岸線、湖岸線、湖中島岸線、湖中島中湖岸線。這裡我們就再使用一次 ``coast`` 把海岸線和國界線用 ``thinner`` 等級的線條來畫畫看,順便再使用 ``-Bafg`` 畫上地圖邊框及格線: We have already introduced ``-I`` and ``-N`` in :doc:`coloring_topography`. The number in ``-W`` can be ``1``, ``2``, ``3``, or ``4``, representing coastline, lake shoreline, shoreline of island-in-a-lake, and shoreline of lake-on-an-island-in-a-lake, respectively. Here we can use ``coast`` again to draw coastlines and country borders using ``thinner`` thickness, and also place ``-Bafg`` to draw the map frame and gridlines: CC-BY-4.0 +"# (前略) +# ==== 主要指令 ==== +gmt begin central_america png + gmt grdimage @earth_relief_01m -JB-80.27/8.58/-8/24/15c -R-100/1/-50/34r -Cgeo + gmt coast -G${color0} \\ + -E${colorgroup1}+g${color1} \\ + -E${colorgroup2}+g${color2} \\ + -E${colorgroup3}+g${color3} \\ + -E${colorgroup4}+g${color4} \\ + -E${colorgroup5}+g${color5} + gmt coast -W1/thinner -N1/thinner -Di -Bafg +gmt end" "# (skipped) +# ==== Main commands ==== +gmt begin central_america png + gmt grdimage @earth_relief_01m -JB-80.27/8.58/-8/24/15c -R-100/1/-50/34r -Cgeo + gmt coast -G${color0} \\ + -E${colorgroup1}+g${color1} \\ + -E${colorgroup2}+g${color2} \\ + -E${colorgroup3}+g${color3} \\ + -E${colorgroup4}+g${color4} \\ + -E${colorgroup5}+g${color5} + gmt coast -W1/thinner -N1/thinner -Di -Bafg +gmt end" CC-BY-4.0 +這次的成品看起來就像這樣: The output map this time looks like this: CC-BY-4.0 +不知道你有沒有發現換了投影方法的同時,邊框的形式也會跟著變化?有關邊框進一步的設定,請參閱\\ :doc:`layout_design`。 Did you notice that the style of the map frame changed after we used a different map projection? To further set up the map frames, please see :doc:`layout_design` for detailed instruction. CC-BY-4.0 +為了清楚的表示海床的深度,最後我們要來加上色階圖例,顯示不同深度對應的顏色。在 GMT 6 中用來畫色階條與色階圖例的指令是 ``colorbar`` (在之前的版本中稱為 ``psscale``)。``colorbar`` 的基本語法為: To show the depth of the seafloor, finally we are going add a colorbar legend showing which color corresponds to which depth. In GMT 6, we can use ``colorbar`` to plot color bars and colorbar legends. (It was called ``psscale`` in the previous GMT version.) The basic syntax of ``colorbar`` is: CC-BY-4.0 +gmt colorbar -D[位置與尺寸] -B[格線、座標間距、標題等資訊] gmt colorbar -D[position_and_size] -B[gridline_ticks_labels_etc] CC-BY-4.0 +``colorbar`` 提供了設定 ``-D`` 的許多不同方法,這裡我們要使用最簡單的一種: ``colorbar`` provides many ways to set up ``-D``. Here we are going to use the simplest one: CC-BY-4.0 +'-Dj[錨點位置]+w[色階條長度]' '-Dj[Anchor_point_position]+w[colorbar_length]' CC-BY-4.0 +``-Dj`` 會使色階圖例被畫在地圖內部的\\ **九宮格錨點**\\ 中的任一個位置。GMT 使用 6 個字母來指定錨點的相對位置,分別是 ``L`` (左側)、``C`` (水平中央)、``R`` (右側)、``T`` (上方)、``M`` (垂直中央)、``B`` (下方)。前三個字母中挑一個加上後三個字母中挑一個,就能得到錨點的位置與相對應的組合: ``-Dj`` places the color bar in one of the **reference points** inside the map. GMT uses six letters to specify the reference point position: ``L`` (left), ``C`` (horizontal central), ``R`` (right), ``T`` (top), ``M`` (vertical middle), and ``B`` (bottom). We pick one letter from ``L, C, R`` and another letter from ``T, M, B`` and combine them together to get the reference point position: CC-BY-4.0 +如果我們想要在圖的中央右側畫上長度為 ``3`` 公分的色階圖例,只要這麼寫就行了: If we want to place a ``3`` cm-long color bar in the inner right side of the map, set the ``-Dj`` option like this: CC-BY-4.0 +下一個 ``-B`` 選項基本上和 ``coast`` 的 ``-B`` 選項方法相同。不過因為色階條的顏色只沿著一維方向變化,我們必須要分開調整 x 軸和 y 軸的設定: The ``-B`` option in ``colorbar`` is basically the same from the ``-B`` option in ``coast``. However, we have to adjust the settings of the x axis and y axis separately because a color bar only changes its color along one direction: CC-BY-4.0 +'-Bx[格線與刻度 (afg 設定)]+l[擺在刻度一側的標籤] -By+l[擺在色階條一端的標籤]' '-Bx[gridline and ticks (afg settings)]+l[label at the tick side] -By+l[label at the end of the colorbar]' CC-BY-4.0 +這裡我們試著使用 ``-Bx3000`` (``afg`` 三種設定都是每隔 ``3000`` 單位繪製一次) 以及 ``-By+lm`` (在色階條一端寫上 ``m`` 這個字)。我們沒有要在有刻度的一側擺上任何標籤,所以在 ``-Bx`` 中的 ``+l`` 可以省略。把 ``colorbar`` 指令擺在 ``coast`` 後面,就能確保它被畫在地圖的頂層: Here we try to use ``-Bx3000`` (this number will be applied to all the ``afg`` settings) and ``-By+lm`` (place ``m`` at one side of the color bar). We don't plan to place anything at the side of map ticks so that we can omit ``+l`` in ``-Bx``. Place the ``colorbar`` command after ``coast`` to ensure it is plotted at the top of the map: CC-BY-4.0 +"# (前略) +# ==== 主要指令 ==== +gmt begin central_america png + gmt grdimage @earth_relief_01m -JB-80.27/8.58/-8/24/15c -R-100/1/-50/34r -Cgeo + gmt coast -G${color0} \\ + -E${colorgroup1}+g${color1} \\ + -E${colorgroup2}+g${color2} \\ + -E${colorgroup3}+g${color3} \\ + -E${colorgroup4}+g${color4} \\ + -E${colorgroup5}+g${color5} + gmt coast -W1/thinner -N1/thinner -Di -Bafg + gmt colorbar -DjRM+w3c -Bx3000 -By+lm +gmt end" "# (skipped) +# ==== Main commands ==== +gmt begin central_america png + gmt grdimage @earth_relief_01m -JB-80.27/8.58/-8/24/15c -R-100/1/-50/34r -Cgeo + gmt coast -G${color0} \\ + -E${colorgroup1}+g${color1} \\ + -E${colorgroup2}+g${color2} \\ + -E${colorgroup3}+g${color3} \\ + -E${colorgroup4}+g${color4} \\ + -E${colorgroup5}+g${color5} + gmt coast -W1/thinner -N1/thinner -Di -Bafg + gmt colorbar -DjRM+w3c -Bx3000 -By+lm +gmt end" CC-BY-4.0 +到目前為止,我們的地圖幾乎已經完成了。剩下的工作,就是讓色階圖例更顯眼,更易判讀。由於色階圖例直接畫在深色的海床上會看不清楚,我們可以在圖例下方填上一層帶有透明度的白色,讓黑色的數字和線條浮現出來。``colorbar`` 的填色指令為: So far, our map is nearly finished. The rest of the work is to make the colorbar legend more visible and more readable. Since it is not clear to see when the colorbar is plotted on the dark sea bed, we can fill the background of the colorbar with a transparent white color and add the contrast to black lines and words. ``colorbar`` uses the following option to fill background: CC-BY-4.0 +'-F+g[顏色]' '-F+g[color]' CC-BY-4.0 +如要指定\\ **透明度**,只要在顏色後方加上 ``@[透明度%]`` 就行了。``@100`` 是完全透明 (等於沒有畫),而 ``@0`` 是完全不透明 (等於不加透明度時的填色)。這邊我們使用 ``-F+gwhite@50`` 來達成我們的目標。另外,由於陸域的地形被國家填色給蓋掉了,導致色階圖例的上半部 (0 至 5000 公尺) 是無用的資訊。為了省略此段的內容,我們可以使用 ``-G`` 選項來指定繪製圖例時使用的色階範圍。語法為 To specify **transparency**, what you need is simply to add ``@[transparency%]``. ``@100`` means completely transparent (which equals nothing), and ``@0`` means completely non-transparent (which equals to the original fill color.) Here we use ``-F+gwhite@50`` to achieve our goal. Besides, Our land topography is overlaid by the country color blocks so that the upper part of the colorbar (0 to 5000 m) is useless information. To skip drawing this part, we can use ``-G`` option for specifying the range of the color bar to be plotted, like this CC-BY-4.0 +'-G[最小值]/[最大值]' '-G[min_value]/[max_value]' CC-BY-4.0 +``最大值`` 可以設定為海平面 (``0``),那最小值呢?別忘了我們可以使用 ``grdinfo`` 來查閱網格檔的基本資訊,只是這次要加上查詢的地理範圍 (``-R``): ``max_value`` can be set to the sea level (``0``), but what about the minimum value? Don't forget that we can use ``grdinfo`` to look at the information of the grid file, but we have to use the geographic area (``-R``) of interest this time: CC-BY-4.0 +"$ gmt grdinfo @earth_relief_01m -R-100/1/-50/34r +# (前略) +/home/whyj/.gmt/server/earth_relief_01m.grd: x_min: -100 x_max: -50 x_inc: 0.0166666666667 (1 min) name: longitude n_columns: 3001 +/home/whyj/.gmt/server/earth_relief_01m.grd: y_min: 1 y_max: 34 y_inc: 0.0166666666667 (1 min) name: latitude n_rows: 1981 +/home/whyj/.gmt/server/earth_relief_01m.grd: z_min: -8434 z_max: 5310 name: elevation (m) +# (後略)" "$ gmt grdinfo @earth_relief_01m -R-100/1/-50/34r +# (skipped) +/home/whyj/.gmt/server/earth_relief_01m.grd: x_min: -100 x_max: -50 x_inc: 0.0166666666667 (1 min) name: longitude n_columns: 3001 +/home/whyj/.gmt/server/earth_relief_01m.grd: y_min: 1 y_max: 34 y_inc: 0.0166666666667 (1 min) name: latitude n_rows: 1981 +/home/whyj/.gmt/server/earth_relief_01m.grd: z_min: -8434 z_max: 5310 name: elevation (m) +# (skipped)" CC-BY-4.0 +注意 ``z_min`` 的值,就是在搜尋區域中最低的像素值。因此,``最小值`` 使用 ``-8434`` 就可以了。完整的選項設定為 ``-G-8434/0``。把 ``-G`` 和 ``-F`` 的設定都加進 ``colorbar`` 指令內,就完成了本章地圖所有的要求。 The value for ``z_min`` is the minimum value in the search region. Therefore, we will use ``-8434`` as the ``min_value``. The full option is ``-G-8434/0``. Add ``-G`` and ``-F`` options into your ``colorbar`` command``, and voila! Your map is done. CC-BY-4.0 +``colorbar`` 預設繪製在腳本中最後一次使用的色階,在本例中為 ``geo``。如果你要使用 ``colorbar`` 繪製不同的色階條,必須使用 ``-C[色階名]`` 來指定色階進行繪圖。 By default, ``colorbar`` draws the colormap that is most recently used in the script, which is ``geo`` in this example, If you want to use ``colorbar`` for plotting a different colorbar, you have to use ``-C[colormap_name]`` for specifying the colormap to plot. CC-BY-4.0 +本章示範的是最基本的色階條繪製方法,如須查閱更多進階的技巧,請參閱\\ :doc:`editing_cpt_colorbar`。 This chapter shows the most basic way to plot the color bar. For advances skills and tips, please see :doc:`editing_cpt_colorbar`. CC-BY-4.0 +"# ==== 設定顏色與對應的國家 ==== +# mexico, brazil, costa rica, dominican +color1='#CD5C5C' +colorgroup1='MX,BR,CR,DO' +# guatemala, venezuela, jamaica, french guiana, bahamas +color2='pink' +colorgroup2='GT,JM,VE,GF,BS' +# united states, puerto rico, nicaragua, guyana +color3='240/230/140' +colorgroup3='US,PR,NI,GY' +# belize, haiti, trinidad and tobago, panama, salvador +color4='0/36/74/4' +colorgroup4='BZ,HT,TT,PA,SV' +# colombia, cuba, honduras, suriname +color5='97-0.52-0.94' +colorgroup5='CO,CU,HN,SR' +# 其他國家 +color0='169' + +# ==== 主要指令 ==== +gmt begin central_america_gmt6 png + gmt grdimage @earth_relief_01m -JB-80.27/8.58/-8/24/15c -R-100/1/-50/34r -Cgeo # 底圖 + gmt coast -G${color0} \\ + -E${colorgroup1}+g${color1} \\ + -E${colorgroup2}+g${color2} \\ + -E${colorgroup3}+g${color3} \\ + -E${colorgroup4}+g${color4} \\ + -E${colorgroup5}+g${color5} # 國家上色 + gmt coast -W1/thinner -N1/thinner -Di -Bafg # 國界與海岸線 + gmt colorbar -DjRM+w3c -G-8434/0 -Bx3000 -By+lm -F+gwhite@50 # 色階條 +gmt end" "# ==== Setting up colors and corresponding countries ==== +# mexico, brazil, costa rica, dominican +color1='#CD5C5C' +colorgroup1='MX,BR,CR,DO' +# guatemala, venezuela, jamaica, french guiana, bahamas +color2='pink' +colorgroup2='GT,JM,VE,GF,BS' +# united states, puerto rico, nicaragua, guyana +color3='240/230/140' +colorgroup3='US,PR,NI,GY' +# belize, haiti, trinidad and tobago, panama, salvador +color4='0/36/74/4' +colorgroup4='BZ,HT,TT,PA,SV' +# colombia, cuba, honduras, suriname +color5='97-0.52-0.94' +colorgroup5='CO,CU,HN,SR' +# other countries +color0='169' + +# ==== Main commands ==== +gmt begin central_america_gmt6 png + gmt grdimage @earth_relief_01m -JB-80.27/8.58/-8/24/15c -R-100/1/-50/34r -Cgeo # basemap + gmt coast -G${color0} \\ + -E${colorgroup1}+g${color1} \\ + -E${colorgroup2}+g${color2} \\ + -E${colorgroup3}+g${color3} \\ + -E${colorgroup4}+g${color4} \\ + -E${colorgroup5}+g${color5} # fill countries with colors + gmt coast -W1/thinner -N1/thinner -Di -Bafg # boundaries and coastline + gmt colorbar -DjRM+w3c -G-8434/0 -Bx3000 -By+lm -F+gwhite@50 # colorbar legend +gmt end" CC-BY-4.0 +「繪製國界與海床地形圖:以 **100W - 50W,1N - 34N** 為邊界,Albers 圓錐投影,地圖橫向寬 **15** 公分。國家使用 6 種不同的顏色著色,為國界和海岸線加上黑色細線條,海底地形使用 ``@earth_relief_01m`` 資料並以 ``geo`` 為色階。最後在地圖的\\ **右側**\\ 畫上 **3** 公分長的色階圖例,每隔 3000 公尺標示海床的深度,色階圖例背景使用透明白來填色。」 """Plot the country and bathymetry map -- map extent is set to **(100W -- 50W,1N -- 34N)** in Albers projection and **15** cm wide. We use 6 different colors to fill country blocks and draw borders and coastlines with a thin black line. The bathymetry data come from the ``@earth_relief_01m`` dataset and are plotted with the ``geo`` color ramp. Finally, we place a **3-cm-tall** color bar on the right side of the map with tick tables at every 3000 m. The background of the legend is filled with transparent white.""" CC-BY-4.0 +"import pygmt + +# ==== 設定顏色與對應的國家 ==== +# 這裡我們利用了 Python 的 Dictionary 資料結構來縮短程式碼! +color_dict = {'MX,BR,CR,DO': '#CD5C5C', # mexico, brazil, costa rica, dominican + 'GT,JM,VE,GF,BS': 'pink', # guatemala, venezuela, jamaica, french guiana, bahamas + 'US,PR,NI,GY': '240/230/140', # united states, puerto rico, nicaragua, guyana + 'BZ,HT,TT,PA,SV': '0/36/74/4', # belize, haiti, trinidad and tobago, panama, salvador + 'CO,CU,HN,SR': '97-0.52-0.94'} # colombia, cuba, honduras, suriname + +color0 = '169' # 其他國家 +dcw_list = [key + '+g' + value for key, value in color_dict.items()] + +# ==== 取得地形資料 ==== +region = [-100, -50, 1, 34] +grid = pygmt.datasets.load_earth_relief(resolution='05m', region=region) + +# ==== 繪圖 ==== +fig = pygmt.Figure() +fig.grdimage(grid, region=region, projection='B-80.27/8.58/-8/24/15c', cmap='geo') +fig.coast(land=color0, dcw=dcw_list) +fig.coast(shorelines='1/thinner', borders='1/thinner', resolution='i', frame='afg') +# 注意這裡我們在色階條的位置字串中加上了 +o1c/0,稍微偏移其位置。 +fig.colorbar(position='jRM+w3c+o1c/0', truncate=[-8000, 0], frame=['x3000', 'y+lm'], box='+gwhite@50') +fig.show() +fig.savefig('central_america_pygmt.png')" "import pygmt + +# ==== Setting up colors and corresponding countries ==== +# Here we take the advantage of Python's dictionary data structure! +color_dict = {'MX,BR,CR,DO': '#CD5C5C', # mexico, brazil, costa rica, dominican + 'GT,JM,VE,GF,BS': 'pink', # guatemala, venezuela, jamaica, french guiana, bahamas + 'US,PR,NI,GY': '240/230/140', # united states, puerto rico, nicaragua, guyana + 'BZ,HT,TT,PA,SV': '0/36/74/4', # belize, haiti, trinidad and tobago, panama, salvador + 'CO,CU,HN,SR': '97-0.52-0.94'} # colombia, cuba, honduras, suriname + +color0 = '169' # other countries +dcw_list = [key + '+g' + value for key, value in color_dict.items()] + +# ==== Get the Earth relief data ==== +region = [-100, -50, 1, 34] +grid = pygmt.datasets.load_earth_relief(resolution='05m', region=region) + +# ==== Plotting ==== +fig = pygmt.Figure() +fig.grdimage(grid, region=region, projection='B-80.27/8.58/-8/24/15c', cmap='geo') +fig.coast(land=color0, dcw=dcw_list) +fig.coast(shorelines='1/thinner', borders='1/thinner', resolution='i', frame='afg') +# Note that we added '+o1c/0' to the original position string to slightly shift the colorbar! +fig.colorbar(position='jRM+w3c+o1c/0', truncate=[-8000, 0], frame=['x3000', 'y+lm'], box='+gwhite@50') +fig.show() +fig.savefig('central_america_pygmt.png')" CC-BY-4.0 +仿造此章節的地圖,畫出南海 (*South China Sea*) 的海底地形與週邊國家圖。座標可使用 ``95E 至 123E``,以及 ``0N 至 26N``。可使用本章節的顏色或自行調整你愛的搭配。 Using a similar fashion from the map in this chapter, make a map of *South China Sea* showing topography and the nearby countries. Use the coordinate ``95E to 123E`` and ``0N to 26N``. You can choose colors from this chapter or design your favorite color combination. CC-BY-4.0 +有沒有辦法把香港與海南島塗上與中國不同的顏色? Is there any way to fill Hong Kong and Hainan Island with a different color from China? CC-BY-4.0 +推薦搭配的軟體或套件 Software and Packages CC-BY-4.0 +GMT 是負責「畫圖」的軟體,只要丟給它適當的數據和選項,它就能為我們畫出漂亮的圖片。正因為它只負責繪圖,我們時常需要搭配其他軟體處理餵給 GMT 畫圖的資料或是編修輸出圖檔。以下就是筆者推薦搭配 GMT 一同安裝並使用的程式套件或是軟體。 GMT is a toolbox for plotting. We feed it with proper data and it draws beautiful pictures for us in return. Because GMT only does the plotting job, we usually need other tools in our workflow, such as preparing the data for GMT or editing the output files from GMT. This page lists some packages I recommend installing when using GMT. CC-BY-4.0 +程式碼編輯器 Text editor CC-BY-4.0 +GMT 使用 UNIX 系統下的 Shell 指令介面的風格設計而成,也就是說它跟其他所有指令列語言一樣,可以先把所有要下的指令寫成腳本或批次檔,再一併執行。使用 PyGMT 的方法則與撰寫 Python 程式語言腳本相同。雖然作業軟體 (尤其是 Windows) 內附的純文字編輯器可以用來寫腳本,但筆者仍然推薦找個更好用的文字編輯器。專為程式設計打造的文字編輯器會有許多附加功能,例如語法標示模式、自動版面調整、簡易除錯等等。以下是幾個常見選擇: We communicate with GMT using a command-line interface, such as the UNIX system’s Shell. That is, we can write all the commands down in a single **script** (or batch file, whatever you call) and have it run like a Python or bash script. For PyGMT, the way to use it is really similar to writing a Python script. Many operating systems have their built-in text editor for writing a script, like Notepad in Windows. However, I highly recommend finding a better text editor crafted for programming. These fancy editors come along with many handy features like syntax highlighting, auto-indentation, basic debugging, etc. The followings are some popular choices: CC-BY-4.0 +本來是為 GNOME 桌面環境 (如 Ubuntu) 製作的輕量級文字編輯器,特點為簡單、易用,並支援語法標示模式,目前更可安裝於所有的作業系統。 Initially designed on GNOME’s desktop (like Ubuntu) as a light-weighted text editor. It’s simple, easy to use, and has syntax highlighting. It has even released on all PC platforms. CC-BY-4.0 +一款很流行而且很強大的程式碼編輯器,各種功能應有盡有,你甚至可以使用愛好者提供的進階模組來增進此軟體,打造屬於你的編輯器。可安裝於所有的作業系統。它是付費軟體,但很佛心的提供終生免費試用。 A popular and powerful code editor with lots of great functions. You can even download extra modules designed by its community, and personalize your own editor. It is available on all platforms and provides a “life-time” trial version, which means you only need to buy the license when you feel worth it. CC-BY-4.0 +由微軟開發的跨平台免費程式碼編輯器,具有一切你想得到的、寫程式時的必備功能,還有不少佈景主題供使用者個人化。更重要的是,VS Code 還支援了 Git 的版本控制,讓使用者可以在同介面中瀏覽修改的檔案,甚至是提交新的更動。 VS Code is a free cross-platform programming editor developed by Microsoft. It has all functionality you can imagine for coding and provides various customized themes. More importantly, VS Code supports Git and version control and allows users to navigate or even commit file changes. CC-BY-4.0 +其他還有 Vim、Emacs、Micro、Nano、Kate、Notepad++ 等等,族繁不及備載,歡迎大家[比較後](https://zh.wikipedia.org/wiki/%E6%96%87%E4%BB%B6%E7%BC%96%E8%BE%91%E5%99%A8%E6%AF%94%E8%BE%83),挑一個自己覺得比較順手的就行了。 Besides, there are other good editors like Vim, Emacs, Micro, Nano, Kate, and Notepad++. Feel free to [compare](https://en.wikipedia.org/wiki/Comparison_of_text_editors) and pick whichever you feel the best. CC-BY-4.0 +Jupyter 專案的核心宗旨是提供開源的軟體與技術標準,並設計互動性的運算界面,服務以不同程式語言進行工作的使用者們。Jupyter 有許多不同的軟體產品,如果你預計使用 PyGMT,那麼我推薦安裝 Jupyter Lab,讓你可以使用網頁瀏覽器作為撰寫腳本時的整合性開發介面。[這裡](https://www.mdeditor.tw/pl/23Lf/zh-tw)有關於 Jupyter Lab 的進一步介紹。在後續章節中提供的 PyGMT 腳本,就是使用 Jupyter Notebook 格式儲存。(*聲明:[本人](https://whyjz.github.io/)現為 Jupyter 的一個子專案 Jupyter Meets the Earth 團隊的一員,本教學中所有關於 Jupyter 的描述皆是我個人意見,並且是我利用閒暇時間所寫成,不代表開發團隊的意見。*) The Jupyter project's core concept is to provide a standard for open-source software and develop interactive computing interfaces for users who work with different programming languages. Jupyter has many software products, and if you plan to use PyGMT, I recommend installing Jupyter Lab because it allows you to use your web browser as an integrated interface for developing your scripts. See [here](https://www.mdeditor.tw/pl/23Lf/zh-tw) for more detailed descriptions about Jupyter Lab. The PyGMT scripts provided in the following chapters are written in the Jupyter Notebook format. (*Disclaimer: [I am currently a team member of the Jupyter Meets the Earth project](https://whyjz.github.io/). All descriptions about Jupyter in these tutorials are my personal opinions and do not represent the Jupyter dev team. I wrote these tutorials using my off-work time.*) CC-BY-4.0 +Jupyter Notebook 是一個透過瀏覽器 (即在伺服器端) 運作的應用程式,透過使用者指定的「核心」如 Python、R、Shell 等程式語言存取電腦的計算資源。使用者可在 Notebook 的圖形化介面中撰寫程式碼與文檔,並在同一份文件中顯示運算結果、插入連結、播放影片等等,使一份工作流程以高度結構化的方式呈現在讀者眼前。 "Jupyter Notebook is an app running on a web browser (i.e. on the server). It uses a user-defined ""kernel"" such as Python, R, or Shell programming language to access the computation resources. Thus, users can write code and documentation together in the Notebook GUI and display execution results in the same document along with external links and video embeds. Readers can see a highly structured and narrative workflow in a Notebook." CC-BY-4.0 +JupyterLab 是 Notebook 的進化版,以控制面板的設計,讓瀏覽不同類型的資料、管理不同的 Notebooks,不同工作流程之間的比較都變得更容易。JupyterLab 也是在本教學中雲端執行程式碼功能 (MyBinder) 的預設圖形化介面。 JupyterLab is the next generation of the Notebook. It introduces the panels into the GUI to view different kinds of data, manage multiple Notebooks, and compare different workflows more easily. JupyterLab is also the default GUI in this tutorial for the interactive cloud environment (MyBinder). CC-BY-4.0 +GMT 原生支援的地理空間資料格式是 **NetCDF** 和純文字檔,不過可透過 GDAL 這個選裝套件的支援直接讀取許多常見的地理空間資料格式,像是 **GeoTIFF** 或是 **shapefile** 等等。GDAL 的全名是「Geospatial Data Abstraction Library」,直譯為「地理空間資料存取函式庫」。它是一個開源且一直持續更新的函式庫,並且支援了 142 種影像格式和 84 種向量格式,可以說功能非常全面。GDAL 本身提供了一些常用指令,可以讓你藉由指令列快速的修改或瀏覽地理空間資料,但它也可以模組的方式在許多程式語言中執行,如 Python。GDAL 可以獨立安裝在各種作業系統中,或是透過 Anaconda 等套件管理軟體進行安裝。請記得如果你想讓 GMT 可以透過 GDAL 的支援讀取更多的資料格式,就要在安裝 GMT 時一併或預先安裝 GDAL。 GMT natively supports some geospatial formats such as **NetCDF** and plain text files and has extended support to other common formats with GDAL, including **GeoTIFF** and **shapefile**. GDAL is short for “Geospatial Data Abstraction Library.” It is open-source software and is constantly updating. As of now, GDAL supports at least 142 raster formats and 84 vector formats. GDAL comes with handy console commands which let you browse or edit geospatial data without pain. Besides, GDAL also serves as a library that can be run as a module in many programming languages such as Python. GDAL can be installed on any platform independently or as a part of the QGIS standard installation since QGIS uses it for manipulating geospatial data. Note that if you want GMT to read more GDAL-supported file formats, you have to install GDAL before installing GMT. CC-BY-4.0 +地理空間資料處理圖形介面 Graphic interface for processing geospatial data CC-BY-4.0 +GMT 的強大之處是在於它對空間資料的數學操作,以及類 Unix 的設計理念,就算是很複雜的製圖需求,都可以只透過短短幾行指令達成;但有的時候,你只是想要快速的看一下你的資料,或是對它們進行一些簡單的處理。這種情況下,安裝一個具有圖形介面的地理資訊系統 (GIS) 處理軟體或許也是不錯的選擇。 GMT is powerful because it manipulates geospatial data with a few command lines, even though you have to make a complex figure. However, there is always time you might just want to browse your data or run some simple tasks. In this case, a graphic interface of GIS for analyzing geospatial data would be your best friend. CC-BY-4.0 +QGIS 是非常著名的 GIS 自由軟體,從 2009 年釋出第一版至今,已經累積了不少使用者和志願協助開發者。除了使用圖形化介面操作以外,它也以 Python 作為腳本語言,方便使用者編寫腳本增進工作效率,甚至自行設計外掛模組。QGIS 可以安裝在各種電腦作業系統,甚至還包括 Android! QGIS is popular free GIS software released in 2009. Numerous users and volunteers have joined the community to make it better. It uses Python as the console language, which makes users efficiently process data in a graphic or script-based fashion. You can also make your plugins to increase working efficiency. QGIS supports various operating systems, even including Android! CC-BY-4.0 +ArcGIS 是一個老牌的 GIS 商業軟體,由 Esri 這間公司一手打造。ArcGIS 其實是一群軟體的統稱:Esri 依照使用者不同的需求,把自家產品往許多方向微調���讓我們可以依照不同的目的選擇最適當的軟體來操作。同樣的,Python 也是 ArcGIS 主流支援的腳本語言,可惜的是目前 ArcGIS 只能安裝在 Windows 中。 ArcGIS is a well-known business GIS software designed by Esri. This name ArcGIS actually refers to a bunch of packages as Esri fine-tunes their products based on various needs, and we can choose the best package to work for different goals. Python is also the scripting language supported by ArcGIS. Unfortunately, ArcGIS is only available on Windows. CC-BY-4.0 +[Google 地球](https://earth.google.com/) [Google Earth](https://earth.google.com/) CC-BY-4.0 +嚴格來講,Google 地球 (Google Earth) 算是「地球儀軟體」,也就是以提供瀏覽地理空間資料為主,而不強調操作或修改這些資料。在 Google 地球中,使用者僅能建立簡單的圖徵,或是瀏覽從別處取得的地理空間資料,不過這在許多狀況中已經很夠用了。目前 Google 地球可以安裝在各種作業系統,當然也有 Android,同時還有一般版與專業版可以選擇。 Strictly speaking, Google Earth is only “Globe software.” We are supposed to view geospatial data using this software instead of editing them. In Google Earth, we can only set up simple features or browse data from other sources. However, this software is still capable of many tasks. Google Earth now supports any platform, including Android, and both standard and professional versions are provided. CC-BY-4.0 +GMT 5 或之前的版本只能以 PostScript (PS) 格式出圖 (請參閱{doc}`basic_concept`),但可以使用 GMT 自帶指令或第三方軟體如 ImageMagick 轉檔。如要檢視 PS 檔又不想安裝專用軟體,可以把它傳到 Google 雲端硬碟上再用 [Google 文件](https://www.google.com/intl/zh-TW/docs/about/) 開啟檔案。 GMT 5 or earlier versions can only generate the PostScript files (see {doc}`basic_concept`), but we can use the built-in commands or a third-party package such as ImageMagick to convert those files. If you want to view PostScript files without installing any software, you can upload them onto Google Drive and use [Google Docs](https://docs.google.com/) to open the files. CC-BY-4.0 +圖檔檢視、處理與編修軟體 Image viewing, processing, and editing software CC-BY-4.0 +從 GMT 6 開始,使用者可以自行選擇出圖的格式,例如向量格式的 PDF 或影像格式的 PNG。難免有些時候,你會覺得 GMT 的出圖還需要一點點額外的編修。除了重新跑一次 GMT 的所有指令外,你也可以使用以下兩個在開放科學圈比較流行的的影像編輯軟體來幫你處理: GMT 6 users can select the output map format, for example, vector-format PDF or image-format PNG. Nevertheless, to tweak the map just a little (e.g., adjusting resolution and image size), it is still easier to use an image processor as it saves your time from rerunning the GMT script. Here I list two popular open-science tools to help expedite your task: CC-BY-4.0 +一款開源的免費圖像處理軟體,由許多不同的指令構成,每個指令都有很多選項可使用,更支援許多不同的向量或影像格式。它使用命令列操作,你可以使用 `convert` 這個指令,輕鬆快速的微調輸出的影像 (如調整解析度與尺寸等等操作)。ImageMagick 目前可以在多種平台上安裝,同時它也是許多 Linux 發行版預裝的軟體之一。 An open-source and free package for image processing. It includes numerous commands; each of them has various options. It also supports many image or vector formats. You can run the command `convert` to easily adjust images. ImageMagick is available on several platforms and is pre-installed on Linux as one of the standard OS packages. CC-BY-4.0 +果你想要使用自由軟體編修向量檔,或是你的作業系統是 Linux,那麼此套軟體是不錯的選擇。它也可在非 Linux 的多種平台上執行。 If you are a fan of free software or you are using Linux, Inkscape would suit you the best for tackling vectorized images. It is also available on non-Linux platforms. CC-BY-4.0 +如果想要使用商業軟體的話,[Adobe Illustrator](http://www.adobe.com/tw/products/illustrator.html) 或是 [CorelDRAW](http://www.coreldraw.com/tw/) 也是不錯的選擇。 If you would like to have the options from the proprietary software, [Adobe Illustrator](https://www.adobe.com/products/illustrator.html) and [CorelDRAW](http://www.coreldraw.com/) are two good ones. CC-BY-4.0 +暈渲地圖 Hillshade Map CC-BY-4.0 +基本概念與名詞 Basic Concepts and Terms CC-BY-4.0 +GMT 繼承了在 UNIX 環境之下處理資料的方法,對於曾經接觸過 shell 或 cmd 的人,它的操作方法應該不陌生。如果你之前完全沒有用過,也沒有關係,以下將提供一些必要的基本概念,稍微熟悉後,就可以快速上手。 GMT inherits the way of how the UNIX system manipulates data. For those who have some experience using Unix shell or cmd, GMT is easy to get started. If you never used anything like that, don't worry about it. This section will introduce some essential concepts for using GMT, which makes you get into the swing of it. CC-BY-4.0 +另外,這裡也會簡單介紹 GMT 相關的一些檔案格式與操作,如果你是第一次接觸地理空間的資料,也歡迎在此查閱相關的術語。 In addition, we will also introduce file formats that are associated with GMT. If it’s your first time using geospatial data, there should be some terms worth to look up at any time. CC-BY-4.0 +UNIX 環境 UNIX environment CC-BY-4.0 +終端機 Terminal CC-BY-4.0 +雖然目前主要的作業系統都是以圖形介面 (桌面) 當作預設的使用者介面,但是你仍然可以透過指令列來控制你的電腦。最簡單的方法就是透過作業系統在桌面環境下內建的指令列程式來執行。指令列程式在 Windows 下稱為 cmd,而 Mac 或大部分 Linux 系統則稱為終端機 (terminal)。在本教學中,「開啟終端機」就意味開啟指令列模式來操作你的電腦。在 Windows XP 之後的版本,有兩種「終端機」可以選擇,一個就是 cmd,另一個稱為「PowerShell」,簡單的說就是讓使用者可以在 Windows 的介面之下使用 UNIX 殼程式 (shell) 的一些語法。在本教學中,所有要在終端機下輸入的指令,最前方都會有個提示符號 Although all the system platforms adopt a graphic interface (desktop) as the default user interface, You still can use command-line tools to get control over your computer. The easiest way to do this is to open a built-in program on the desktop environment. The program is called **cmd** on Windows, or **terminal** on Mac or most Linux systems. In this tutorial, to “open the terminal (app)” means to control your computer using a command-line tool. On Windows XP or later versions, there are actually two terminals on a single platform: cmd and “PowerShell.” The latter enables the usage of Unix shell’s syntax. In this tutorial, we always put a prompt sign at every command you need to type on the terminal CC-BY-4.0 +接在 ``$`` 之後的文字,才是使用者真正要輸入的指令。有關如何開啟作業系統的指令模式,請參考相關的專書或網頁,於此不再贅述。 The words after the ``$`` symbol are what users actually type. If you got any questions on how to open the terminal on your system platform, please check up related textbooks and webpages for the detailed step-by-step. CC-BY-4.0 +殼層 (Shell) Shell CC-BY-4.0 +簡單的說來,殼層指的是使用者和「電腦這台機器」進行互動的介面,像是 Windows 的桌面環境、或是某個作業系統的指令列程式,都稱之為殼層。不同的殼層有不同的與電腦互動的方法,例如在文字介面殼層中,使用者要下達預先定義的指令,才能命令電腦做事。最初的 GMT 使用者介面,就是建立在一個很有名的、指令列程式型的殼層之中,它叫做 **sh**。經過了長時間的發展,GMT 已經被移植到了不同作業系統下的指令列殼層,例如說 Windows 的 cmd,但是 GMT 的指令語法仍然維持著原本殼層的格式。基本上,你可以把這些格式直接視作 GMT 指令操作的一部分來學習。有關於殼層的基本語法,許多資訊科學的專書或網頁均有詳細介紹,例如\\ `鳥哥的Linux 私房菜 `_。會一點殼層的指令,絕對對操作 GMT 有莫大的助益。 Generally speaking, a shell refers to the interface between a user and a machine such as your PC. That means either the Desktop environment on Windows or the command console on other platforms counts. The way to interact with a computer varies from different shells. Let’s take the text-based shell for instance: a user needs to type a pre-defined command to make the computer work. GMT was initially designed and built on a famous command-line shell called **sh**, but now it has been developed and transplanted into other shells on other platforms, like the cmd on Windows. Nevertheless, GMT has remained its original style in terms of the syntax. It is recommended to learn the shell syntax together with the GMT commands. If you would like to learn more about the shell syntax, there are many textbooks or online sources that are comprehensive and well-written, like `Ryans Tutorials `_. Getting some knowledge of shell would definitely make you more confident with GMT. CC-BY-4.0 +有一個語法倒是非常值得一記,那就是註解符號 ``#``,例如以下指令: There’s a syntax worth mentioning here: the comment mark ``#``. For example: CC-BY-4.0 +$ gmt grdinfo 你的檔案.grd # 觀看檔案的資訊 $ gmt grdinfo yourfile.grd # view info of the file CC-BY-4.0 +在 ``#`` 後面的文字,是對指令的補充說明。本教學中,也會使用此格式,使腳本更易於閱讀。 The words following the ``#`` are the additional description of the command. In this tutorial, we will use the format to make our scripts easier for reading. CC-BY-4.0 +批次檔或腳本 Scripts, aka Batch files CC-BY-4.0 +在指令列程式中,每按下一次 ``Enter`` 鍵,就會立刻執行當下的指令。但使用者也可以選擇把所有想要執行的程式統一寫在一個純文字檔中,然後在指令列程式輸入檔名,電腦就會逐一讀取文字檔中的指令並執行。在 Windows 中,這種檔案叫做「批次檔 (batch file)」,而在 sh 或由它衍生的各種殼層中,通常會稱為「腳本 (script)」,但基本上他們指的是同一件東西,在本教學中,將統一稱之為「腳本」。不同系統在執行腳本的操作細節上,會有些許差異,而且通常也有許多種方式可以讀取腳本。以下是筆者推薦的操作方法。 Whenever you press ``Enter`` on a command console, the computer starts to run the command you just put immediately. A user, however, can also opt to write down all the commands in a single text file, and type the name of the text file into the command line, then the computer would read the content and runs over all commands in order. On Windows, these files are called “batch files,” but they are also usually called “scripts” on Bourne shell or other related shells. They have the same function no matter the names they bear. In this tutorial, we choose to call them “scripts” regardless of platforms for the best readiness. You usually have many ways to get your script run, and there is also some difference among platforms in terms of processing details. I recommend the following several ways to do this. CC-BY-4.0 +Windows: 把 ``.txt`` 腳本檔案的副檔名改成 ``.bat``,然後點兩下此檔,Windows 就會自動開啟 cmd 來執行。一般來說,腳本的最後一行可以放上 Windows: change the file extension from ``.txt`` to ``.bat``, and double-click the file. Windows will automatically open cmd and run it. You can also put the following line at the bottom of your file CC-BY-4.0 +"...(以上都是你的指令) +pause" "...(your commands) +pause" CC-BY-4.0 +加上 ``pause`` 之後,腳本執行完不會直接關閉 cmd 視窗,你可以在手動關閉前,先看一下所有指令的執行情況。 ``pause`` command prevents cmd from closing the command window after running the script. It makes you be able to check the progress of all the commands in your script before manually closing the window. CC-BY-4.0 +Unix 為基礎的系統 (Linux 或 Mac 等等): 副檔名可以隨便命名,筆者通常偏好以 ``.sh``、``.csh`` 或 ``.bash`` 結尾,端看你想要用哪種殼程式進行操作。以 bash 為例,腳本的第一行可以放上 Unix-based system (Linux, Mac, etc.): there’s no regulation of file extension, but I usually prefer using ``.sh``, ``.csh``, or ``.bash``, depending on which shell you are going to use. Take bash as an example; it is convenient to put this at the first line of the script (it’s called **sheband**): CC-BY-4.0 +"#!/bin/bash +...(以下都是你的指令)" "#!/bin/bash +...(starting your commands)" CC-BY-4.0 +然後在指令列中,改變檔案權限 And then change the file permission at the command prompt CC-BY-4.0 +$ chmod +x 你的腳本.bash $ chmod +x yourscript.bash CC-BY-4.0 +這樣要執行時,就可以直接下達如下指令,非常方便: And now you can run your script by typing this: CC-BY-4.0 +$ 你的腳本路徑/你的腳本.bash $ path_to_your_script/yourscript.bash CC-BY-4.0 +在本教學中,\\ **所有的 GMT 腳本都是以 bash 語法編寫**\\ 。雖然不管你使用的是哪種作業系統或殼程式,GMT 的指令都會相同,但是因為腳本中難免會出現隨著殼程式不同而變化的語法,因此如果你使用的是除了 bash 之外的其他殼 (csh、tcsh、cmd、Power Shell 等等),本教學的腳本在執行之前,可能需要小幅的修改成符合你使用的殼的語法,尤其是像指定變數、迴圈、建立檔案、文字資料處理等等的操作。 In this tutorial, **all the GMT scripts are written in bash format**. Although the GMT commands never change through platforms or shells, you still need to be aware of the syntax that varies with the shell. If you are using other shells than bash (like csh, tcsh, cmd, Power Shell…), you may have to modify the script a little bit so it adapts to another shell. This is especially true for operations like assigning variables, looping, reading and writing some files, and text-file processing. CC-BY-4.0 +至於在本教學中出現的 PyGMT 腳本...當然就是以 `Python`_ 語言撰寫的啦! For the PyGMT scripts in the tutorial... of course, they are written in `Python`_! CC-BY-4.0 +地理空間資料 Geospatial data CC-BY-4.0 +NetCDF 是 Network Common Data Form 的縮寫,直譯為「網路通用數據格式」。顧名思義,他是一種儲存資料的格式,由 UCAR (美國大氣研究大學聯盟) 在 1989 年開始設計、發展到現在。NetCDF 最初的目標,是要為科學資料提供一種統一的儲存格式,以方��研究人員互相傳遞資料。除了設計儲存格式外,UCAR 也為 netCDF 編寫了一系列的模組與函數庫,讓使用者可以簡單的在各種程式語言或環境中操作這些資料。NetCDF 是 GMT 主要支援的檔案格式,常見的附檔名為 ``.nc``,不過有時也會用 ``.grd`` 副檔名,來表示它的資料結構。它以二進位模式儲存資料,而且除了資料數據本身外,也附有檔頭描述這些數據的基本資訊 (這些檔頭通常稱為「中繼資料」,英文是 Metadata)。NetCDF 還有一個特點,就是它的資料跟作業系統的\\ `位元儲存序 `_\\ 無關,使用者不須擔心資料傳給別人後會讀取錯誤。其他詳細的說明,請參閱 `netCDF 網站 `_。 NetCDF, or “Network Common Data Form,” is a data type developed by UCAR (University Corporation for Atmospheric Research). First released in 1989, the initial goal of NetCDF is to provide a standard for scientific data storage, as it’s convenient in terms of data sharing. In addition to data format, UCAR has also released a set of modules and libraries that enable users to access data with different environments or programming languages. NetCDF is the main file format GMT supports, commonly seen as the ``.nc`` extension, but sometimes ``.grd`` is also used for clarifying its data structure. NetCDF data are saved in binary value, with a text-based header (also usually called as “metadata”) for describing associated data. The advantage of NetCDF format is that the data have nothing to do with your system’s byte order, and that’s great news since you don’t have to worry that people can’t read your data correctly when you are sharing files with them. For more details, please go to the `NetCDF website `_. CC-BY-4.0 +大地座標系統 (Datum) Geodetic datum CC-BY-4.0 +大地座標系統,就是一批用以描述地球形狀的參數,以及運用這些參數計算出來的地球表面的三維座標。目前全世界最通用的大地座標系統為 **WGS84** (又稱之為 **EPSG:4326**),它也是 GPS 衛星所採用的大地座標系統。 A geodetic datum is a set of parameters for describing the shape of the Earth. We need it to calculate the coordinates of any place on the Earth. The most common geodetic datum now is **WGS84** (aka **EPSG:4326**), which is also adopted by GPS satellites. CC-BY-4.0 +以 WGS84 為例,它把地球的形狀定義成兩極略扁的橢球,橢球的中心對準地球的質心。這個形狀通常稱為 **WGS84 參考橢球**。此外在地表的水平座標設定上,緯度原點是赤道大圓,經度子午線原點則稍稍偏離了格林威治天文台。 In WGS84, the shape of the Earth is defined as an oblate spheroid with flattened poles. The center of the oblate spheroid is at Earth’s center of mass. This shape is often called the **WGS84 reference ellipsoid**. When calculating the surface coordinates, the latitude zero is set at the equator, and the longitude zero is a little bit away from the Royal Observatory in Greenwich. CC-BY-4.0 +簡而言之,大地座標系統就是一整套幫地表設定三維座標 **(經度,緯度,高度)** 的參數集合。GMT 預設的大地座標系統也是 WGS84,你也可以使用以下指令查看現在 GMT 的座標系統: In a nutshell, we use geodetic datum to set up coordinates (**Latitude, Longitude, Height**) at any location on the Earth. The default datum of GMT is WGS84, and you can also check the current datum by this command: CC-BY-4.0 +$ gmt defaults -D # 在 Projection Parameters 的欄位 $ gmt defaults -D # inside the block of Projection Parameters CC-BY-4.0 +而關於地表的垂直高度,WGS84 表示的數值則是與\\ `大地水準面 `_\\ 的差距。目前 WGS84 使用 **EGM96** 這個地球的重力模型來設定地球的大地水準面。 WGS84 uses the difference between the surface and the `geoid `_ as the altitude of the surface. Currently, WGS84 adopts **EGM96**, a gravitational model, as the standard of geoid. CC-BY-4.0 +大地座標系統基本上是不會定義垂直高度的參考基準的,它必須要由使用者自己決定。目前常用的基準有兩個: A geodetic datum doesn't define the basis of vertical elevation. It means users have to determine how to measure the altitude of topography. There are two commonly used standards: CC-BY-4.0 +直接用參考橢球的表面當基準測量高度,稱之為\\ **橢球高**。 Measure the vertical difference between topography and the reference ellipsoid. This is called **Ellipsoidal Height**. CC-BY-4.0 +使用海水面 (`大地水準面 `_\\) 當基準測量高度,稱之為\\ **正高**。目前常用的標準為 **EGM96** 這個地球的重力模型。 Measure the vertical difference between topography and sea surface (`geoid `_). This is called **Orthometric Height** or **Geoid Height**. **EGM96** is the most commonly used gravitational model for deriving geoid location. CC-BY-4.0 +慣例上,以 WGS84 做基準的資料都會採用\\ **正高**\\ 來表示高度,但並非所有的資料都會遵循這條規則。如果你對高度有精細的要求,例如誤差須在數十公尺內,最好確認一下你的資料是使用哪種高度參考基準。 Data based on WGS84 usually use **Orthometric Height** to represent elevation, but not all data follow this convention. If it is required to have a small uncertainty on elevation, like within 10 meters, it would be better to check which way the height was measured. CC-BY-4.0 +投影法與投影座標系統 (Projected Coordinate System) Projection and Projected Coordinate System CC-BY-4.0 +由於大部分的地圖都是平面的,再加上我們畫區域性的地圖時,經緯度也沒那麼方便 (1 度是 100 多公里,如果地圖很小,常常都只會有幾弧分或幾弧秒的改變),所以在許多時候,我們會使用特定的投影法,把地球的弧面依照某種幾何公式拓展成平面,這樣地圖上一個點的座標,就可以用 **(二維 X 座標,二維 Y 座標,高度)** 來表示。這種座標表示法,就稱作投影座標系統。 Unlike the curved surface of the Earth, most maps are flat. Moreover, it would be awkward to use Lat/Long for a regional map because 1 degree is usually around 110 km, which is way larger than the size of many cities and towns. Therefore, in many cases we would stretch and flatten the Earth’s surface using a specific projection (which is actually a set of geometric formulae). Any location on a map can thus be written as a 3-D coordinates **(X, Y, Height)**. This way to represent geographical locations is called Projected Coordinate System. CC-BY-4.0 +要創造投影座標系統,必須要指定地球的形狀 (也就是大地座標系統中的參考橢球) 和投影法。目前全球最通用的投影座標系統稱為 **UTM**,是 Universal Transverse Mercator 的縮寫,中文為「全球橫麥卡托投影」。它使用 WGS84 的參考橢球,把地球切割成許多區域,每個區域個別使用\\ `橫麥卡托投影法 `_\\ 來製作地圖的二維座標。 We need both the shape of Earth (aka reference ellipsoid in the geodetic datum) and a projection to make a (projected) coordinate system. The most popular projection coordinate system is **UTM**, or Universal Transverse Mercator, which uses WGS84 ellipsoid. It cuts the Earth into 60 zones (except the polar region), and apply the `Transverse Mercator `_ projection to each zone with different coordinate origin. CC-BY-4.0 +如果想要知道更多有關投影法的細節與不同投影法和投影座標系統的介紹,可以參考\\ `臺師大的地圖投影解說 `_\\ 或\\ `上河文化的解說網頁 `_。 For more introductions on projections and projected coordinate systems, `ArcGIS online webpages `_ provide good explanations over these topics. CC-BY-4.0 +除了 WGS84 外,台灣還有兩個常用的大地座標系統,稱為 **TWD67** 與 **TWD97**,與之對應的投影座標系統則是 TWD67-TM2 與 TWD97-TM2。這兩個大地座標系統設定的地球橢球體外型,都跟 WGS84 不一樣,其中 TWD67 的差距較大,導致算出來的座標會與 WGS84 有數百公尺至一公里的差距;而 TWD97 就非常的接近 WGS84,在台灣地區的座標差距大致上只有數十公分。\\ [1]_ In addition to WGS84, there are other two widely-used sets of geodetic datum called **TWD67** and **TWD97** for regional maps of Taiwan. The corresponding projected coordinate systems are TWD67-TM2 and TWD97-TM2, respectively. Both two sets adopt a different reference ellipsoid from WGS84, but TWD87 has a greater offset, which often results in a distance of 0.1-1 km from WGS84 Lat/Long. TWD97, on the other hand, is relatively close to WGS84, with only a range of several tens of centimeters. [1]_ CC-BY-4.0 +GMT 6 的新語法模式 The new syntax mode in GMT 6 CC-BY-4.0 +在 2019 年秋季釋出的 GMT 6 是目前最新的 GMT 版本,也是本手冊內文指令使用的版本。製作團隊在此版本中,引進了一個全新的語法系統,稱為現代模式 (Modern Mode),以和 GMT 第五版與之前的傳統模式 (Classic Mode) 區別。在現代模式中,GMT 把 PostScript 的繪圖步驟轉移到暫存檔中,並直接產生向量形式的 PDF 或是影像形式的 PNG 與 JPG,因此大大簡化了腳本的繁雜程度。以下列出現代模式和傳統模式最主要的差別\\ [2]_\\ : GMT 6 is released in 2019 and is the latest version of GMT. It is also the version this tutorial is based on. It introduces a brand new system of syntax, called the **Modern Mode**, to highlight the difference from the old syntax GMT 5 was using (called the **Classic Mode**). In the modern mode, GMT saves its PostScript-formated map into a temporary file, and directly generate a vector PDF or an image PNG/JPG to the user. This way greatly reduces the complexity of a GMT script. I have listed some major differences between the modern mode and the classic mode here: [2]_ CC-BY-4.0 +GMT 指令不再透過 UNIX 的輸出重導向 (``>``) 把地圖存到 ``.ps`` 檔中。 GMT commands no longer use UNIX's redirecting symbol ``>`` to save a map to a ``.ps`` file. CC-BY-4.0 +使用者不用再透過 ``-O`` 與 ``-K`` 選項「連接」不同的 GMT 指令。 "Users don't need to use ``-O`` and ``-K`` to ""connect"" multiple GMT commands anymore." CC-BY-4.0 +因為可以直接選擇多種出圖格式,使用者不用再花費時間轉檔。 Because you can now directly specify many different map formats, it saves your time from converting your final maps. CC-BY-4.0 +出圖的版面尺寸不再綁定紙張尺寸,而是會自動裁切到繪圖區域的大小。因此,``-P`` 選項也不需要了。 The map size is no longer fixed to the paper size. Instead, GMT now automatically crops the map to the plotting area. Thus, you don't need the ``-P`` option anymore. CC-BY-4.0 +許多 ``ps`` 開頭的指令改了名字,多半是把 ``ps`` 刪掉,但也有完全改掉的例子,例如 ``psxy`` 變成了 ``plot``。 Many commands starting with ``ps`` have changed their names. Most of them just have the ``ps`` removed, but few of them have a completely new name now. For example, ``psxy`` in GMT 4-5 is ``plot`` in GMT 6. CC-BY-4.0 +在現代模式中,使用者\\ **必須**\\ 要透過 ``gmt begin`` 與 ``gmt end`` 來包住繪圖的指令。在傳統模式中無此語法。 In the modern mode, you **have to** use ``gmt begin`` and ``gmt end`` to wrap the other plotting commands. You cannot find these two commands in the classic mode. CC-BY-4.0 +重複的繪圖區域 ``-R`` 和投影 ``-J`` 等設定,再也不用在每一個指令中都列出。 Now you don't need to repeatedly list map extent ``-R`` and projection ``-J`` in each GMT command. CC-BY-4.0 +增加了 ``subplot`` 指令,讓製作多合一地圖變得很容易。 There is a new command called ``subplot`` to expedite the task to make multi-frame maps. CC-BY-4.0 +為了向下相容使用舊版語法的腳本,在 GMT 6 中你可以使用現代模式或是傳統模式的語法。因為新的語法具有許多優點,\\ **在本教學手冊中,我會使用現代模式的語法來撰寫腳本**\\ 。然而,在部份繪製地圖的章節中,我也會一併放上傳統模式的教學連結以及使用傳統模式撰寫的腳本,供各位使用者參考。 To make the backward compatibility, in GMT 6 you can use either modern mode or classic mode to write your script. Because there are many advantages of the new syntax, **for this tutorial I use the modern mode syntax to create maps.** However, I will also provide a link to the script using the classical mode and the associated instruction in some chapters for your reference. CC-BY-4.0 +如果你已經是 GMT 5 的使用者,可以馬上無痛升級到 GMT 6,因為幾乎所有第五版的語法在第六版中都有支援 (傳統模式)。 If you are already using GMT 5, then you might want to update to GMT 6 right now because the new version supports almost all GMT 5 syntax (as the classic mode). CC-BY-4.0 +如果你已經是 GMT 4 的使用者,以下列出幾個例子顯示 GMT 6 (傳統模式) 與 GMT 4 指令上的不同: If you are already using GMT 4, the following cases show the difference between GMT 4 and GMT 6 (classic mode) in terms of commands: CC-BY-4.0 +"$ pscoast 各種選項... # GMT 4 的 pscoast 指令 +$ gmt coast 各種選項... # 在 GMT 6 中,換成了 coast 指令,而且變成總指令 gmt 下屬的一個模組。 +$ gmtset 各種選項... # GMT 4 的 gmtset 指令 +$ gmt set 各種選項... # 在 GMT 6 中也換成了 set 指令,而且變成總指令 gmt 下屬的一個模組。" "$ pscoast options... # pscoast command in GMT 4 +$ gmt coast options... # In GMT 6, it is replaced by the coast command, which is a module of the main gmt command. +$ gmtset options... # gmtset command in GMT 4 +$ gmt set options... # In GMT 6, it is also replaced by the set command, which is a module of the main gmt command." CC-BY-4.0 +然而,在安裝 GMT 6 的時候,系統會問你要不要替所有 ``gmt`` 指令下屬的模組建立捷徑。如果你選了 Yes,那麼你就可以使用 GMT 4 的語法來讓 GMT 6 執行你的腳本 (意思就是,GMT 會讓系統理解 ``pscoast`` 等等 GMT 的舊指令名字)。 However, when installing GMT 6 the system would ask you if you want to generate shortcuts for all the ``gmt`` modules. If you choose Yes, then you can use the GMT 4 syntax in GMT 6 (i.e., GMT can make system understand the old GMT commands such as ``pscoast``). CC-BY-4.0 +PyGMT 的工作環境 The working environment of PyGMT CC-BY-4.0 +Python 與 PyGMT Python and PyGMT CC-BY-4.0 +Python 是\\ `現在最流行的一種程式語言 `_。如果您對 Python 有興趣,網路上有非常多的學習資源。因為它非常流行,所以在 GMT 使用者社群中一直存在一股想法,就是希望能透過 Python 使用 GMT 的各項功能。GMT 是以 `C 語言 `_\\ 開發的,如果要使用 Python 存取 GMT 的函式庫,就要透過 API (應用程式介面,Application Programming Interface) 才能順利達成。GMT 的 API 本質上是額外的程式碼,但你可以把它想像成是不同線材的轉接頭,讓本質上是 C 語言的 GMT 函式庫能夠理解 Python 傳來的指令。PyGMT 就是透過 API 來下達繪圖指令給 GMT,並且再把 GMT 的回傳值 (地圖、數據等等) 整理成與 Python 相容的數據結構。這種軟體也稱為包裝庫 (Wrapper library)。 Python is the `most popular programming language at the present time `_. If you are interested in learning Python, there is a lot of onboarding resources available online. Thanks to its popularity, there has been an idea in the GMT user community: it would be great if we could access GMT through Python. GMT is based on the `C programming language `_, which means you have to use an API (Application Programming Interface) to access the GMT library in Python. The GMT's API is essentially some code, and it is analogous to the adapter for different cables. In other words, the API makes the GMT library understand the control commands from Python. PyGMT uses such an API, sends tasks to GMT, and converts the return values (data, map, etc.) into some Python-compatible formats. We also call this kind of software package a wrapper library. CC-BY-4.0 +PyGMT 的語法簡介 The PyGMT syntax CC-BY-4.0 +PyGMT 把每張地圖視作一個\\ `物件 `_,然後透過物件的\\ `方法 `_\\ 來執行所有的繪圖指令。以 GMT 6 的 ``coast`` 指令來說,在 PyGMT 下你要這樣執行: PyGMT treats a map as an `object `_ and executes all the plotting commands through the object's `methods `_. For example, you have to use this way to run the ``coast`` command in GMT 6: CC-BY-4.0 +"import pygmt # 首先必須匯入 PyGMT 模組! +fig = pygmt.Figure() # 建立地圖物件 +fig.coast(各種選項...) +# 最後再用 fig.show() 螢幕出圖,或是 fig.savefig(...) 儲存圖檔" "import pygmt # First off, you have to import the PyGMT module! +fig = pygmt.Figure() # Make a map object +fig.coast(options...) +# Finally, use fig.show() to show the map on the screen, or use fig.savefig(...) to save to disk" CC-BY-4.0 +``coast`` 指令的各種選項,在 GMT 中是以 UNIX 風格的「旗標」模式指定,例如 ``-R``、``-J`` 等等。而在 PyGMT 中,不同的旗標被賦予了全名,並以參數值的格式輸入到物件方法中,例如 ``-R`` 對應到 ``region``,``-J`` 對應到 ``projection`` 等等。以下是來自「\\ :doc:`making_first_map`\\ 」的更詳細對照: "GMT uses the UNIX-style ""flags"" to assign various options of the ``coast`` command, for example, ``-R`` and ``-J``. In PyGMT, These flags are all changed to a more meaningful name and are passed into the object method as an argument. For example, ``-R`` is renamed as ``region``, and ``-J`` corresponds to ``projection``. Here are some more translations from :doc:`making_first_map`:" CC-BY-4.0 +"# 使用 GMT 時... (在 shell 腳本中) +gmt coast -R... -J... -W... -G... -B... +# 使用 PyGMT 時... (在 python 腳本中) +fig.coast(region=..., projection=..., shorelines=..., land=..., frame=...)" "# When using GMT... (in a shell script) +gmt coast -R... -J... -W... -G... -B... +# When using PyGMT... (in a python script) +fig.coast(region=..., projection=..., shorelines=..., land=..., frame=...)" CC-BY-4.0 +在 PyGMT 的使用手冊中,可以找到更詳細的\\ `選項對照表格 `_。 In the PyGMT user manual, you can check the more detailed `parameter list and their aliases `_. CC-BY-4.0 +Jupyter Notebook 與 Binder Jupyter Notebook and Binder CC-BY-4.0 +本教學手冊中使用兩種 PyGMT 腳本的格式。除了傳統的純文字 HTML 語法顯示外,也提供了 `Jupyter Notebook `_ 的 Binder 連結。點開 Binder 連結後,伺服器端會安裝一個可以執行 PyGMT 的環境,然後你就可以透過你的網頁瀏覽器執行與修改教學手冊中的 PyGMT 程式碼。本功能目前使用 `MyBinder.org `_ 提供、利用 Amazon Web Services 的雲端運算服務讓各位都能免安裝就體驗 PyGMT。歡迎各位多加嘗試! This tutorial uses two different formats for PyGMT scripts. In addition to the traditional pain text rendered as HTML, I also provide them as `Jupyter Notebooks `_ as well as their Binder links. The Binder link will lead you to a server that installs a PyGMT environment for you, and you can run, modify, and try these PyGMT scripts using your web browser. I currently use the service from `MyBinder.org `_ which uses the cloud computing resources at Amazon Web Services so that everyone can try PyGMT without installing it. Feel free to give it a try! CC-BY-4.0 +XY 點散佈圖 Scatter Plot CC-BY-4.0 +本教學適用於 GMT 6 的現代模式。如須參閱 GMT 6 (傳統模式) 與 GMT 4-5 繪製相似地圖的教程,\\ `請至這裡 `_。 This instruction is for the Modern Mode in GMT 6. For making the same map using the GMT 6 Classic Mode or GMT 4-5, `Please go to this page `_ (only final script available). CC-BY-4.0 +在數據分析中最重要也最常用的圖表形式,非 XY 散佈圖莫屬。雖然 GMT 是繪製地圖的專門工具,但它仍然能處理跟地理空間無關的資料,並做出精美的視覺化分析。在本章中,將會解說用來繪製點、線、面的重要指令 ``plot`` (舊版 GMT 內為 ``psxy``),以及一些衍伸的作圖設定技巧。這些技巧在處理地理空間資料時也都適用。 The most common and important graph type for data analysis is definitely X-Y scatter plots. We have learned that GMT is excellent for making maps, but in fact, it is also capable of processing non-spatial data and visualized them pretty well. In this chapter, we will introduce a command used to draw points, lines, and polygons: ``plot`` (or ``psxy`` in older versions of GMT). We will also show some associated tricks for plotting figures, which are useful for both spatial and non-spatial data. CC-BY-4.0 +使用台灣\\ *中央氣象局*\\ 的氣象資料,製作風速 (Wind Speed) 對氣溫 (Temperature) 的 XY 散佈圖。圖中使用了 2016 年 1 月,位於竹子湖 (Zhuzihu) 與蘇澳 (Su'ao) 兩個測站的每日資料,並用不同顏色與不同標記表示。在圖中可以看出幾點有趣的事情: Using the data from the *Central Weather Bureau*, Taiwan, Make an X-Y scatter plot showing wind speed versus temperature. We use the daily weather data in January 2016 from two weather stations: Zhuzihu (竹子湖) and Su'ao (蘇澳). Each station is labeled with a distinct color and marker. We can see something interesting from the plot: CC-BY-4.0 +風速與氣溫看來呈現負相關,也就是說,氣溫越低,風速越快。 There is a negative correlation between wind speed and temperature; that is, the lower the temperature, the faster the wind blows. CC-BY-4.0 +一般來說,竹子湖的氣溫要比蘇澳來得冷一點,而且蘇澳在一月份還有超過攝氏 20 度以上的日子。 The temperature in Zhuzihu is usually lower than Su'ao. Also, there are still few days warmer than 20 degrees Celcius in Su'ao. CC-BY-4.0 +竹子湖有一天的溫度掉到了攝氏 0 度以下。事實上,這天是竹子湖睽違了 11 年後,再度下雪的日子\\ [#]_。這些受「超級寒流」影響的資料點,看起來就像是整個負相關趨勢的離群值。 "There was one day when the temperature in Zhuzihu dropped below 0 degrees Celcius. In fact, this is a special snow day since Zhuzihu had had no snowfall for 11 years before 2016 [#]_. The temperature on that day, influenced by a ""super winter front,"" looks like an outlier in the overall scattering trend." CC-BY-4.0 +``info`` - **查閱純文字格式數值資料檔的基本資訊** ``info`` - **display basic information from a text-based numeric data file** CC-BY-4.0 +``plot`` - **繪製點、線與多邊形** ``plot`` - **plot points, lines, and polygons** CC-BY-4.0 +``basemap`` - **設定繪圖區、座標軸與邊框** ``basemap`` - **set up mapping area, axes, and map frame** CC-BY-4.0 +``text`` - **在圖上標記文字** ``text`` - **Make text labels in a map** CC-BY-4.0 +外部指令 ``echo`` - **把資料輸入到管線命令中** External command ``echo`` - **pass input data through a pipe** CC-BY-4.0 +GMT 共用選項:``-JX`` (直角座標作圖) GMT shared options: ``-JX`` (Cartesian plot) CC-BY-4.0 +如何輸入 ASCII (純文字) 格式的資料到 GMT 中 How to import ASCII (text) data to GMT CC-BY-4.0 +如何從螢幕或腳本輸入資料到 GMT 中 (標準輸入重導向) How to import data to GMT via terminal or a script (standard input, aka stdin) CC-BY-4.0 +繪製 XY 散佈圖 Plot a 2-D scatter plot CC-BY-4.0 +設定座標軸標籤與特殊文字的處理方法 How to place an axis label and how to deal with special characters/formats CC-BY-4.0 +製作簡易的圖例 Make a simple legend CC-BY-4.0 +我們這次使用的資料是\\ **中央氣象局的天氣觀測紀錄**\\ 。這些資料可以從中央氣象局建置的「\\ `觀測資料查詢系統 `_\\ 」取得。選擇位於臺北市 (TaipeiCity) 的竹子湖 (ZHUZIHU) 測站,資料格式為「月報表」,時間為 2016 年 1 月,按下查詢鈕後,應該會看到如下頁面: "We will use the data from the **Central Weather Bureau's observations**. The dataset is available at the `CWB observation data inquire system `_. Select ""TaipeiCity"", ""ZHUZIHU"", and ""monthly data"" in the dropdown menu, and specify the time to January 2016. Press the ""Query (查詢)"" button, and you should see the following page:" CC-BY-4.0 +把表格全選後複製貼上到 *Microsoft Excel* 或 *Libre Office Calc* 之類的試算表軟體,資料就會自動對到不同的欄位。接下來,你可以選擇以下兩種作法的任一種: Select all content in the sheet, copy and paste them to an application like *Microsoft Excel* or *Libre Office Calc*. Next, you can choose one of the following two methods: CC-BY-4.0 +直接在試算表軟體中刪除不要的資料,只留「氣溫」與「風速」兩欄。把第一列「檔頭列」(也就是欄位名稱) 也刪除,接著「另存新檔」為逗號分隔檔 (``.csv`` 檔)。 Delete all unnecessary data in the software except for the columns for Temperature and Wind Speed. Delete the header row (the first row with names of the columns) as well. Then save it as a ``.csv`` comma-separated file. CC-BY-4.0 +把第一列「檔頭列」(欄位名稱) 刪除,「另存新檔」為逗號分隔檔 (``.csv`` 檔),再使用 shell 指令操作逗號分隔檔。例如在大部分的 Linux shell 下,可以使用 Delete the header row (names of the columns), and save it as a ``.csv`` comma-separated file. Then use shell commands to process the CSV file. For example, you can use this in the most Linux shells: CC-BY-4.0 +$ cut -d ',' -f 8,17 你的檔案.csv > zzh.txt $ cut -d ',' -f 8,17 yourfile.csv > zzh.txt CC-BY-4.0 +其中第 8 欄和第 17 欄分別就是「氣溫」與「風速」的資料。 Here the columns 8 and 17 are the data of temperature and wind speed, respectively. CC-BY-4.0 +處理完的 ``zzh.txt`` 檔可以直接使用文字編輯器打開,前幾欄應該會長這樣 The output file ``zzh.txt`` can be opened directly in a text editor. The first few rows should look like this: CC-BY-4.0 +"14.6,3.6 +15.7,0.2 +16,0.3 +17.7,0.3 +17.8,0.7 +# ....以下略.... +# 第 1 欄:氣溫 (攝氏);第 2 欄:風速 (公尺/秒)" "14.6,3.6 +15.7,0.2 +16,0.3 +17.7,0.3 +17.8,0.7 +# ....(skipped).... +# Column 1: Temperature (Celcius); Column 2: Wind Speed (m/sec)" CC-BY-4.0 +如此一來資料就整理成 GMT 的輸入格式了。再次使用同樣流程,可以取得位於宜蘭縣 (YiLanCounty) 的蘇澳 (SU-AO) 測站的相同資料,把它命名為 ``suao.txt``。GMT 並不依據副檔名讀取純文字資料,但是相對的,它只接受四種欄位分隔符號:\\ **空格**、**Tab**、**逗號**\\ 與\\ **分號**。在把資料輸入 GMT 前,務必確認你的資料能被 GMT 正確讀取。 Now we are done setting data up to the GMT-compatible input format. Using the same workflow again, we can also get the dataset from the Su'ao (SU-AO) station (YiLanCounty at the first dropdown menu). Rename the processed GMT-compatible to ``suao.txt``. GMT doesn't need the ``.txt`` file extension when loading text data, but you have to make sure you use one of the following four characters to separate your columns: **space**, **tab**, **comma**, or **semicomma**. Before plotting the data, Remember to make sure your data can be loaded by GMT correctly. CC-BY-4.0 +事實上,你也可以不用刪除任何檔頭和欄位,只要把資料存成 ``.csv`` 檔或其他 GMT 能接受的純文字格式,GMT 自己就有帶有功能選項來讀取資料表中的特定欄位,請參考 `GMT 官方手冊的說明 `_。 Actually, you can choose not to delete any headers and columns. As long as you save your data as a ``.csv`` file or other GMT-acceptable text format, there are options in the GMT commands that can parse the datasheet and only load part of the dataset you want. Please see `GMT Official Manual `_ for more details. CC-BY-4.0 +為了方便起見,你也可以直接從以下連結取得本章節會使用的檔案: For your convenience, you can also download the data used in this chapter from this link: CC-BY-4.0 +``plot`` 是用來把點資料描繪到地圖上的工具。對於一般不與地理座標相關的資料,在畫���時的 ``-J`` 選項是 ``-JX``,GMT 會使用單純的直角座標來畫圖。至於要怎麼決定 ``-R`` 的範圍?你可以先使用 GMT 內附的 ``info`` 指令簡單地查閱一下純文字資料的資訊,像這樣: ``plot`` is a tool for plotting point data on a map. When plotting non-spatial data, we use ``-JX`` as the ``-J`` option, and GMT will use Cartesian coordinates to set up the figure. But what about ``-R``? You can use the built-in GMT command ``info`` to check the information of the text data real quick, like this: CC-BY-4.0 +"$ gmt info zzh.txt +zzh.txt: N = 31 <-0.4/17.8> <0.2/6.3> +# 檔名 資料點數 第一欄最小/最大值 第二欄最小/最大值" "$ gmt info zzh.txt +zzh.txt: N = 31 <-0.4/17.8> <0.2/6.3> +# Filename Datapoints Column1-Max/Min Column2-Max/Min" CC-BY-4.0 +由於第一和第二欄的數值會分別被用在 x 軸和 y 軸,我們馬上就可以依照最大和最小值決定 ``-R`` 的範圍。``info`` 指令也可以接受多於一個的輸入檔,只要所有檔案的欄位數量相同即可。如下所示: Since the values from the first and the second column will be used for x and y, we can determine the range of ``-R`` based on their minimum and maximum values. ``info`` command can also accept more than one input files as long as all the files have the same amount of columns. The syntax goes the following: CC-BY-4.0 +"$ gmt info zzh.txt suao.txt +dataset: N = 62 <-0.4/21.6> <0.2/6.3> +# 資料點數 第一欄最小/最大值 第二欄最小/最大值" "$ gmt info zzh.txt suao.txt +dataset: N = 62 <-0.4/21.6> <0.2/6.3> +# Datapoints Column1-Max/Min Column2-Max/Min" CC-BY-4.0 +依照 ``info`` 的輸出資料,我們可以知道所有的資料點一定能畫在 ``-R-1/23/0/7`` 的範圍內 (x 從 -1 至 23,y 從 0 至 7)。馬上來畫畫看我們的資料: According to the output message from ``info``, we know that all the data points can be shown within ``-R-1/23/0/7`` (x from -1 to 23; y from 0 to 7). Let's take a look at our data: CC-BY-4.0 +雖然資料是畫上去了,不過這並不是我們想要的樣子...這是因為 ``plot`` 的預設繪圖模式為\\ **折線圖**\\ ,會把所有的點以線連接起來,如果我們只想要 ``plot`` 畫點,必須要加上 ``-S`` 選項。此選項除了使 ``plot`` 轉換成\\ **散佈圖**\\ 模式外,還可以使用以下語法設定資料點的樣式: Ok, there are data in the figure, but this isn't what we expected. This is because the default ``plot`` mode is **line chart**, which connects all the data points with lines. If we want only points using ``plot``, we have to add the ``-S`` option. This option turns ``plot`` into the **scatter plot mode** and has the following syntax to set up the style of data points: CC-BY-4.0 +'-S代號[尺寸]' '-S[code][size]' CC-BY-4.0 +``代號`` 為單一字元的符號,而尺寸指定的東西則依符號的不同而不同。完整的代號列表可以在 `plot 的說明頁面 `_\\ 找到。舉個例子,``-Sc0.25c`` 是把資料點設為直徑為 0.25 cm 的圓形 (``c``,circle),而 ``-Sd3c`` 則是外接圓直徑為 3 cm 的菱形 (``d``,diamond)。**如果不給尺寸的話,GMT 會尋找資料檔案中的第三欄,並且以其數值當作對應的資料點的尺寸**。這個規則在我們要畫不同大小的資料點時,非常方便。在這裡,我們的資料只有 x 與 y 兩欄,因此把所有的點設成一樣大小就行了。另外,你會發現繪圖區目前是 15 cm x 15 cm 的正方形,如果你想要任意調整 X 或 Y 軸的長度的話,需要在 ``-JX`` 後分開指定,如 ``-JX15c/10c`` 會把 X 軸設成 15 cm,Y 軸設成 10 cm。讓我們使用以上新增的選項,重畫一次看看: ``code`` is a single character indicating different shapes, and what is referred to as ``size`` varies when the shape changes. The full list of the ``code`` is available at the `manual page of plot `_. For example, ``-Sc0.25c`` means to plot data with circles (``c``) with a diameter of 0.25 cm, and ``-Sd3c`` means diamonds (``d``) whose circumcircle size is 3 cm. **If size is omitted, GMT will find the third column in the data table and use the number from there as the size of each point**. This rule is especially convenient when we want to plot points with different sizes. Here our data table only has two columns -- x and y -- so that all the points will be in the same size. Also, you may find that the map now is a 15-by-15 cm square. If you would like to adjust the length of the x or y axis separately, you have to specify that after ``-JX``. For example, ``-JX15c/10c`` sets the x-axis length at 15 cm and the y-axis length at 10 cm. Use these new options and draw our figure again: CC-BY-4.0 +"$ gmt plot zzh.txt -R-1/23/0/7 -JX15c/10c -Sc0.35c -G#58C73A -W0.03c,black -Baf -png zzh +# -G: 標記填色 +# -W: 標記外框畫筆" "$ gmt plot zzh.txt -R-1/23/0/7 -JX15c/10c -Sc0.35c -G#58C73A -W0.03c,black -Baf -png zzh +# -G: Marker filling +# -W: Marker frame pen" CC-BY-4.0 +選擇了適當的標記樣式與填色,與粗一點的標記框線,看起來就會美觀許多。 Now the figure looks much better after changing a good combination of marker fill, style, and a thicker pen. CC-BY-4.0 +``plot`` 除了可以從檔案中讀取資料外,也可以從標準輸入 (standard input, ``stdin``) 讀取資料。這樣一來,我們就可以直接在腳本或命令列中給定座標點。常見的作法有兩種: In addition to loading data from a file, ``plot`` can also reads data from the standard input (``stdin``). By doing this, we are able to give coordinates in the script or the terminal. There are two common ways to achieve this: CC-BY-4.0 +使用管線命令,把前一個指令的輸出傳給 ``plot``。例如在各種作業系統終端機都有的 ``echo`` 指令: Use the pipe command and pass the output from the previous command to ``plot``. For example, this shows the ``echo`` command that is available in many OS terminals: CC-BY-4.0 +"$ echo ""10.2 3.2"" | gmt plot -選項們" "$ echo \\""10.2 3.2\\"" | gmt plot [-options]" CC-BY-4.0 +如此一來,(10.2, 3.2) 就會被當成座標點畫在圖上。 Hence, (10.2, 3.2) will be plotted as a data point. CC-BY-4.0 +使用標準輸入重導向搭配結束的輸入字元 (``<<`` 符號): Redirect the standard input using the ``<<`` characters at the end of a line: CC-BY-4.0 +"$ gmt plot -選項們 << END +...任意的多行資料... +END" "$ gmt plot -options << END +...Multi-line data table... +END" CC-BY-4.0 +在 ``<<`` 符號後可以為任意的字符串,此例為 ``END``。從下一行開始,一直到第二個 ``END`` 的前一行,都會被當作 ``plot`` 的輸入資訊。 The string after the ``<<`` characters can be anything you like. We use ``END`` here, for example. Starting from the next line, all the content here until the last line before we meet ``END`` again will be used as the data for ``plot``. CC-BY-4.0 +為了完成本章目標,我們需要在 *x = 0* 之處畫一條灰色的垂直虛線,以表明有一個點溫度低於零度。運用 ``plot`` 預設的繪線模式與上述的第二種作法,就可以簡單的畫出。在以下的腳本中,我們順便把第二組數據也畫上去了,使用標記是藍色的菱形: One of the chapter goals is to draw a gray vertical line at *x = 0*, which represents a point with temperature below the freezing point. We can simply draw this using the default mode of ``plot`` and the second way described above. In the following script, we also plot the second dataset using the blue diamond as point marks: CC-BY-4.0 +"# ==== 設定變數 ==== +zzh='zzh.txt' +suao='suao.txt' + +gmt begin windspeed_vs_temperature png + # ==== 繪點 ==== + gmt plot $zzh -R-1/23/0/7 -JX15c/10c -Sc0.35c -G#58C73A -W0.03c,black -Baf + gmt plot $suao -Sd0.35c -G#3A6BC7 -W0.03c,black + + # ==== 灰色垂直虛線 ==== + gmt plot -W0.03c,100,-- << LINEEND +0 0 +0 7 +LINEEND + +gmt end" "# ==== Setting variables ==== +zzh='zzh.txt' +suao='suao.txt' + +gmt begin windspeed_vs_temperature png + # ==== Scatter plot ==== + gmt plot $zzh -R-1/23/0/7 -JX15c/10c -Sc0.35c -G#58C73A -W0.03c,black -Baf + gmt plot $suao -Sd0.35c -G#3A6BC7 -W0.03c,black + + # ==== Gray vertical line ==== + gmt plot -W0.03c,100,-- << LINEEND +0 0 +0 7 +LINEEND + +gmt end" CC-BY-4.0 +這條灰色的線寬度是 0.03 cm,並且連接 (0, 0) 與 (0, 7) 兩點。 The width of the gray line is 0.03 cm. It connects two points: (0, 0) and (0, 7). CC-BY-4.0 +注意在輸入多行資料的時候,資料和結束字元前面不能有任何空格,這就是為什麼以上的腳本有三行不縮排的原因。如果你覺得這樣不美觀,可以使用另一種標準輸入重導向字元 ``<<-``,不過你的\\ **縮排字符限定只能使用 tab**,如下所示: Note that when entering multi-line data in the script, no space is allowed at the beginning of any line, including the ending characters. This is why we don't indent those three lines in the script. If you think this isn't that beautiful, there is another stdin redirection symbol ``<<-`` you can use, but keep in mind that **you can only use tab as the indentation character** with this symbol, as shown here: CC-BY-4.0 +"# (前略) +gmt begin windszzh.txtpeed_vs_temperature_gmt6 png + # ==== 繪點 ==== + gmt plot $zzh -R-1/23/0/7 -JX15c/10c -Sc0.35c -G#58C73A -W0.03c,black -Baf + gmt plot $suao -Sd0.35c -G#3A6BC7 -W0.03c,black + + # ==== 灰色垂直虛線 ==== + gmt plot -W0.03c,100,-- <<- LINEEND + 0 0 + 0 7 + LINEEND +gmt end" "# (skipped) +gmt begin windszzh.txtpeed_vs_temperature_gmt6 png + # ==== Scatter plot ==== + gmt plot $zzh -R-1/23/0/7 -JX15c/10c -Sc0.35c -G#58C73A -W0.03c,black -Baf + gmt plot $suao -Sd0.35c -G#3A6BC7 -W0.03c,black + + # ==== Gray vertical line ==== + gmt plot -W0.03c,100,-- <<- LINEEND + 0 0 + 0 7 + LINEEND +gmt end" CC-BY-4.0 +``<<-`` 重導向字元會把資料結束字元前面的 ``tab`` 區塊移除,使 ``LINEEND`` 結束字元能夠正確的被讀取。 ``<<-`` redirection characters remove any ``tab`` blocks at the beginning of a line so that ``LINEEND`` ending characters can be read correctly. CC-BY-4.0 +``plot`` **無法同時畫線又畫點**。如果你有這方面的需求 (例如繪製折線圖),需要使用兩次 ``plot`` 指令,畫完線後再把點也標上去。 ``plot`` **can not draw lines and points at the same time** If you want to do this (for example, when making a line chart), you need to use ``plot`` twice, putting lines first and points later. CC-BY-4.0 +不知你是否覺得,以上腳本實在說不上美觀,要改動也很麻煩?問題的原因,出在第一個 ``plot`` 指令。為了設定 ``-R``、``-J`` 與一些額外設定,第一個 ``plot`` 指令硬是會比第二個 ``plot`` 要長。考慮到這兩個指令在繪圖中有等量的效果 (都是畫上一組數據的散佈圖),如果有更適當的方式,能夠先把該設定的選項設定好,讓兩個 ``plot`` 的效果看起來更直觀就好了。 What do you think about the current script? For me, this doesn't look so pretty because of its first ``plot`` command. It is much longer than the second ``plot`` command because we have to set up ``-R``, ``-J``, and some other things for the first time. Since these two commands are doing quite the same thing, it would be better to set up other options before the first ``plot`` comes so that they can be straightforward. CC-BY-4.0 +這時候,總算輪到 ``basemap`` 指令上場!``basemap`` 是\\ **專門用來設定底圖與邊框樣式**\\ 的指令。在短的腳本中,我們可以透過其他指令附帶的 ``-B`` 或是其他選項來設定底圖與邊框,但是當腳本一長,或是當你想要調整許多有關的預設選項時,使用 ``basemap`` 可以讓你的腳本看起來更清晰易懂。讓我們再次回到這兩行指令 It's finally time to introduce the ``basemap`` command! ``basemap`` lets you set up, of course, the basemap and the frame style. In a short script, we can use the ``-B`` option in many commands to adjust the basemap settings. However, when your script gets longer, or there are many settings about your map, I would suggest using ``basemap`` since it would make your script clear and more readable. Let's revisit these two lines CC-BY-4.0 +我們可以把地圖的通用選項移到 ``basmap`` 中,因此以上指令也可以寫成這樣 We can move all the general settings to the ``basemap`` command, and the script becomes to CC-BY-4.0 +如此一來,兩行 ``plot`` 指令各自的功用就一目了然:它們只是處理並繪製不同的資料點,但繪製的方法是相同的。你可以把所有選項與語法格式都互相對齊以求美觀,而所有通用的設定,包括 ``-R``、``-J``、``-B`` 等,全部都丟到 ``basemap`` 就對了。 Now it makes more sense to these two lines of ``plot`` commands: they read and plot data points in the same way, but using different markers and colors. You can also align all the options to make your script prettier. Remember: just toss all general options, like ``-R``, ``-J``, ``-B``, to the ``basemap`` command, and you are all set. CC-BY-4.0 +現在腳本的第一個指令是以 ``basemap`` 開頭。當然,我們可以在這個指令中一併設定標題與座標軸標籤。在「\\ :doc:`making_first_map`\\ 」中,我們有提到標題可以使用 ``-B+t`` 添加,而在「\\ :doc:`editing_cpt_colorbar`\\ 」中,我們也提到了要使用 ``-B[x或y]+l`` 添加座標軸的標籤。因此,我們就來添加一些文字說明吧: Now the script begins with a ``basemap`` option. We can set up the title and the axis label in this line as well. In :doc:`making_first_map`, we learned how to add a title using ``-B+t``; and in :doc:`editing_cpt_colorbar`, we also mentioned that the axis label is governed by ``-B[x_or_y]+l``. Follow these instructions and add some text in the map: CC-BY-4.0 +"# ==== 設定變數 ==== +zzh='zzh.txt' +suao='suao.txt' +zzh_style=""-Sc0.35c -G#58C73A -W0.03c,black"" +suao_style=""-Sd0.35c -G#3A6BC7 -W0.03c,black"" + +gmt begin windspeed_vs_temperature png + # ==== 版面與作圖區設定 ==== + # -Baf 現在拆成了 -Bxaf 與 -Bya2f, + # 你可以分開給定 x 軸與 y 軸的 a、f、g 選項! + gmt basemap -R-1/23/0/7 -JX15c/10c -B+t""January 2016"" \\ + -Bxaf+l""Temperature (degree C)"" -Bya2f+l""Wind Speed (m s-1)"" + # ==== 繪點 ==== + gmt plot $zzh $zzh_style + gmt plot $suao $suao_style + + # ==== 灰色垂直虛線 ==== + gmt plot -W0.03c,100,-- << LINEEND +0 0 +0 7 +LINEEND + +gmt end" "# ==== Setting variables ==== +zzh='zzh.txt' +suao='suao.txt' +zzh_style=""-Sc0.35c -G#58C73A -W0.03c,black"" +suao_style=""-Sd0.35c -G#3A6BC7 -W0.03c,black"" + +gmt begin windspeed_vs_temperature png + # ==== Settings about the map ==== + # -Baf now becomes -Bxaf and -Bya2f + # and you can specify a, f, and g options for x and y axes separately! + gmt basemap -R-1/23/0/7 -JX15c/10c -B+t""January 2016"" \\ + -Bxaf+l""Temperature (degree C)"" -Bya2f+l""Wind Speed (m s-1)"" + # ==== Scatter plot ==== + gmt plot $zzh $zzh_style + gmt plot $suao $suao_style + + # ==== Gray vertical line ==== + gmt plot -W0.03c,100,-- << LINEEND +0 0 +0 7 +LINEEND + +gmt end" CC-BY-4.0 +以上腳本的出圖如下: Here's the output figure: CC-BY-4.0 +嗯,座標軸標籤會同時出現在上下及左右兩邊,看起來有點多餘;另外,縱軸的單位 ``m s-1`` (公尺/秒) 的 ``-1`` 應該要上標,才是正確的寫法。除此之外,如果 ``degree C`` 能夠直接表示成 ``°C`` 的話,更顯得簡潔有力。要做到以上修改並不困難,首先,我們可以使用 ``-BWSne`` 選項讓左邊和下方顯現座標軸和其標籤,而右邊和上方只顯示座標軸。如果要在文字中顯示上下標,需要加上 **GMT 專用的控制字元** ``@``。``@+`` 是上標,``@-`` 則是下標。被上下標控制字元包起來的字就會顯示為上下標。因此,我們只要把 ``m s-1`` 改成 ``m s@+-1@+`` 即可。攝氏度數的符號也可以使用此控制字元來顯示,代號是 ``@.``。 Hmm, now the axis labels appear at all sides, which is a bit redundant. And the unit of the vertical axis ``m s-1`` (m/s) is not correct writing; the ``-1`` here should be superscripted. In addition, if we can rewrite ``degree C`` as ``°C``, it would be more clear to read. It's not hard to make these changes. First, we can use the ``-BWSne`` option to make axis ticks and labels appear at the west and the south side. Only the axis lines would show up at the east and the north side. If you want to superscript/subscript characters, you need to use the **GMT control character** ``@``. ``@+`` is to toggle superscription on/off, and ``@-`` is to toggle subscription on/off. Any letters enclosed by the control characters will be superscripted/subscripted. Therefore, we can change ``m s-1`` to ``m s@+-1@+`` to achieve our goal. The degree symbol is also available using the control character -- it's ``@.``. CC-BY-4.0 +嚴格說來,``@+`` 控制的是上標的開啟與關閉,因此 ``m s@+-1`` 其實就能使 ``-1`` 上標。然而,筆者建議還是養成良好習慣,頭跟尾都加上控制字元,不只易於判讀跟修改,也跟 `LaTeX `_ 的語法概念類似。有關控制字元可操作的其他字串設定,請參考 `GMT Cookbook `_。 Strictly speaking, ``@+`` toggles the superscription on/off so that ``m s@+-1`` would suffice for our need. However, I still suggest to add the control characters at both ends so that it's easier to read and edit. This style also resembles the `LaTeX `_ writing guide. For other details regarding what the GMT control character can do, please see the `GMT Cookbook `_. CC-BY-4.0 +把以上更動整理到腳本中,「版面與作圖區設定」的部份就會變成這樣: "Let's modify our script based on the changes above and the ""Settings about the map"" section will become this:" CC-BY-4.0 +"# ==== 版面與作圖區設定 ==== +gmt basemap -R-1/23/0/7 -JX15c/10c -BWSne+t""January 2016"" -Bxaf+l""Temperature (@.C)"" -Bya2f+l""Wind Speed (m s@+-1@+)""" "# ==== Settings about the map ==== +gmt basemap -R-1/23/0/7 -JX15c/10c -BWSne+t""January 2016"" -Bxaf+l""Temperature (@.C)"" -Bya2f+l""Wind Speed (m s@+-1@+)""" CC-BY-4.0 +修改後的座標軸看起來就清爽多了! Now, these axes look much better! CC-BY-4.0 +為了完成 XY 散佈圖,我們最後還得加上圖例,告訴讀者兩筆不同資料代表的意義。GMT 本身其實備有 ``legend`` 指令,用來繪製豪華的圖例,但在本例子中,我們將會示範另一種比較「土法煉鋼」,但是較為直觀的作法,這種作法對於簡單的圖例繪製是綽綽有餘。首先,我們要畫一個圖例框架,``plot`` 又會再次派上用場。如果要用 ``plot`` 畫封閉的多邊形,只要指定所有的頂點座標,然後輔以 ``-G`` 指定填色,圖中所有的頂點就會連起來形成多邊形。以下的腳本片段,會以 (16, 5)、(22, 5)、(22, 6.5) 和 (16, 6.5) 為頂點,畫一個顏色為 ``#E6F4F2`` 的矩形。你可以把此片段插在 ``gmt end`` 之前: To finalize our scatter plot, we need to add a legend telling readers the meanings of the two datasets. GMT has ``legend`` command to draw legends as fancy as you like, but here in this example, we will show you how to make a simple legend using a more straightforward method. It is much easier to learn than ``legend`` for a simple legend. To begin with, we need a legend box, and ``plot`` can do the job. To draw a closed polygon using ``plot``, we have to assign all the vertex points and specify the ``-G`` option in the command. And then, it will connect all the points by the given order and form a polygon. The following script snippet uses (16, 5), (22, 5), (22, 6.5), and (16, 6.5) as the vertices and fills the rectangular polygon with the color ``#E6F4F2``. You can insert this snippet before ``gmt end``: CC-BY-4.0 +"# ==== 圖例框與圖例內容 ==== +gmt plot -W0.05c,black -G#E6F4F2 << BOXEND +16 5 +22 5 +22 6.5 +16 6.5 +BOXEND" "# ==== Legend box and its content ==== +gmt plot -W0.05c,black -G#E6F4F2 << BOXEND +16 5 +22 5 +22 6.5 +16 6.5 +BOXEND" CC-BY-4.0 +接下來,圖例框中需要放入之前使用過的符號與相對應的文字說明。符號同樣可以透過 ``plot`` 繪製,這次我們使用 ``echo`` 指令與管線命令,來把前面用的符號畫到圖例框中。當然,你必須要自己決定符號出現的座標,如下所示: Now we have to put the previously used markers and the corresponding labels. ``plot`` can draw the markers for us. This time, we use ``echo`` and the pipe commands to plot the symbols in the legend box. Of course, you have to determine their coordinates first. Like this: CC-BY-4.0 +畫完符號後,只要再標上文字說明,本章目標就大功告成。GMT 具有 ``text`` 指令,可以在指定的座標擺上給定的文字。``text`` 的用法與 ``plot`` 極為相似,只不過至少要有三欄輸入資料,**前兩欄為 xy 座標,第三欄為欲顯示的文字**。另外,``text`` 還具有專有的文字格式調整選項 ``-F``。``-F`` 下比較重要的選項為 After drawing the symbols, the final last goal in this chapter is to put labels explaining them. GMT has ``text`` command to show text at given coordinates. ``text`` is similar to ``plot`` in terms of the syntax, but you need at least three columns in your input data instead of two. **The first two columns are the x-y coordinates, and the third column is the text to be labeled**. Also, ``text`` has its own option ``-F`` to adjust the details of the text. Some important options under the ``-F`` flag are CC-BY-4.0 +'-F+f[字形屬性]+j[對齊錨點位置] # 實際上不只這些,但其餘暫略' '-F+f[word_attributes]+j[anchor_point] # There are more in fact, but we are not going to talk about them here' CC-BY-4.0 +其中 ``字形屬性`` 的給定方法非常類似畫筆屬性,由 ``字體大小,字體名稱,顏色`` 三個參數所構成。這裡我們暫時只改動字體大小為 14 點 (``14p``),其餘維持預設。(更多給定字形屬性的細節請參閱\\ :doc:`layout_design`)。``對齊錨點位置`` 則是沿用上一章「\\ :doc:`pen_and_painting`\\ 」提到的\\ **九宮格錨點**\\ 位置來告訴 GMT 文字的對齊方法,例如我們等下要使用的 ``+jML`` 會讓文字「靠左對齊、垂直置中」給定的座標點。輸入文字的指定整體來看就如下所示: The way to specify ``word attributes`` is similar to that to specify pen attributes. It consists of 3 parameters: ``font size, font name, color``. Here we only change the font size to 14 points (``14pt``) and leave the other settings by default. (See :doc:`layout_design` for more details about the word attributes.) ``Anchor point`` follows in concept from the previous chapter :doc:`pen_and_painting`. It uses a **2-character combination** to tell GMT how to align the text. For example, ``+jML`` (which we are going to use here) will align the left side of the text and the (horizontal) center to the given coordinates. The full command to input text will look like this: CC-BY-4.0 +第一行會把 (18, 6.05) 設為 ``Zhuzihu`` (竹子湖) 文字的最左側,而第二行則是使用相同的指令設定 ``Su'ao`` (蘇澳) 文字出現的地方,圖例到此就設計完成! In the first line, ``Zhuzihu`` is left aligned to (18, 6.05). The second line follows the same way, but the aligned point has shifted. Now your legend is done! CC-BY-4.0 +``text`` 也可以讓使用者一次輸入多個字串,所以其實這兩行 ``text`` 指令也可以寫成 ``text`` also accepts multi-line data input. So these two lines of ``text`` commands can be rewritten using the stdin redirection: CC-BY-4.0 +兩種寫法效果一模一樣,端看你喜歡哪種都可以。事實上,``text`` 也接受多欄的輸入,這樣一來你可以把所有想輸入的文字都寫在檔案內,再分別指定不同的顏色、文字格式等等。詳細說明請參閱\\ :doc:`layout_design`。 This has the same effect from the first method we used in the chapter, so it is only a question which style you like more. Also, ``text`` accepts the input data with more than 3 columns so that you can writing everything down in the text file and assign each line with a distinct color, word attributes, etc. Please see :doc:`layout_design` for more details. CC-BY-4.0 +"# ==== 設定變數 ==== +zzh='zzh.txt' +suao='suao.txt' +zzh_style=""-Sc0.35c -G#58C73A -W0.03c,black"" +suao_style=""-Sd0.35c -G#3A6BC7 -W0.03c,black"" + +gmt begin windspeed_vs_temperature png + # ==== 版面與作圖區設定 ==== + gmt basemap -R-1/23/0/7 -JX15c/10c -BWSne+t""January 2016"" -Bxaf+l""Temperature (@.C)"" -Bya2f+l""Wind Speed (m s@+-1@+)"" + + # ==== 繪點 ==== + gmt plot $zzh $zzh_style + gmt plot $suao $suao_style + + # ==== 灰色垂直虛線 ==== + gmt plot -W0.03c,100,-- << LINEEND +0 0 +0 7 +LINEEND + + # ==== 圖例框與圖例內容 ==== + gmt plot -W0.05c,black -G#E6F4F2 << BOXEND +16 5 +22 5 +22 6.5 +16 6.5 +BOXEND + + echo ""17 6.05"" | gmt plot $zzh_style + echo ""17 5.45"" | gmt plot $suao_style + echo ""18 6.05 Zhuzihu"" | gmt text -F+f14p+jML + echo ""18 5.45 Su'ao"" | gmt text -F+f14p+jML +gmt end" "# ==== Setting variables ==== +zzh='zzh.txt' +suao='suao.txt' +zzh_style=""-Sc0.35c -G#58C73A -W0.03c,black"" +suao_style=""-Sd0.35c -G#3A6BC7 -W0.03c,black"" + +gmt begin windspeed_vs_temperature png + # ==== Settings about the map ==== + gmt basemap -R-1/23/0/7 -JX15c/10c -BWSne+t""January 2016"" -Bxaf+l""Temperature (@.C)"" -Bya2f+l""Wind Speed (m s@+-1@+)"" + + # ==== Scatter plot ==== + gmt plot $zzh $zzh_style + gmt plot $suao $suao_style + + # ==== Gray vertical line ==== + gmt plot -W0.03c,100,-- << LINEEND +0 0 +0 7 +LINEEND + + # ==== Legend box and its content ==== + gmt plot -W0.05c,black -G#E6F4F2 << BOXEND +16 5 +22 5 +22 6.5 +16 6.5 +BOXEND + + echo ""17 6.05"" | gmt plot $zzh_style + echo ""17 5.45"" | gmt plot $suao_style + echo ""18 6.05 Zhuzihu"" | gmt text -F+f14p+jML + echo ""18 5.45 Su'ao"" | gmt text -F+f14p+jML +gmt end" CC-BY-4.0 +「以兩個不同氣象站的 2016 年 1 月風速與氣溫觀測資料,繪製 XY 散佈圖。攝氏 0 度以灰色垂直線表示。圖例、座標軸皆已清楚的標示。」 """Make an XY scatter plot using the wind speed and temperature data recorded in January 2016 from two weather stations. Gray dashed vertical line represents the zero degrees Celcius. Information is given in the legend and in the axis labels.""" CC-BY-4.0 +觀看\\ `最終版圖片`_ Check the `final figure`_ CC-BY-4.0 +本章使用的資料事實上是依照時間排序的,每日只有一個測量數值。因此,請利用本章中提供的數據,畫出竹子湖與蘇澳測站在 2016 年 1 月份的氣溫每日變化的\\ **折線圖**。 The data used in this chapter are timely ordered. They only have one measurement each day. Please use the same data to plot a **line chart** showing the temperature vs time in January 2016 for both Zhuzihu and Su'ao stations. CC-BY-4.0 +請利用 ``plot`` 畫出「`大衛之星 `_」。 Please draw the `Star of David `_ using ``plot``. CC-BY-4.0 +`頻果日報,2016 年 1 月 24 日新聞 `_。 `Apple Daily, 2016/1/24 `_。 CC-BY-4.0 +為地形圖上色 Color the Topography CC-BY-4.0 +本教學適用於 GMT 6 的現代模式。如須參閱 GMT 6 (傳統模式) 與 GMT 4-5 繪製相同地圖的教程,\\ `請至這裡 `_。 This instruction is for the Modern Mode in GMT 6. For making the same map using the GMT 6 Classic Mode or GMT 4-5, `Please go to this page `_. CC-BY-4.0 +把地圖依照不同屬性、在不同區域著色,可以把龐大的資料有效視覺化。最常用來著色的屬性,高度絕對是其中之一。在典型的地形圖中,不同的海拔高度會套上不同的顏色。本章中將會詳細說明如何利用地表的不同高度,製作彩色的地形圖。 To effectively visualize spatial data, one can use different colors on the map based on different values. One of the most frequently used datasets for coloring map is the surface elevation. For a classical topological map, a specific color corresponds to a particular altitude. In this chapter, we are going to see how to make a colored topological map using elevation data. CC-BY-4.0 +製作一張\\ `的的喀喀湖`_ (Lago Titicaca) 的分層設色地形圖,如下圖所示。的的喀喀湖位於秘魯和玻利維亞交界,面積達 8372 平方公里。特殊的是,湖面位置的海拔高達 3812 公尺,是全世界最高的商業通航湖泊\\ [#]_。圖中的藍色線條表示河流,注意右側的河流其實是亞馬遜河的源頭,而且並沒有和的的喀喀湖連接。黑色的虛線是兩國國界。地形圖的顏色從海拔 0 至 5000 公尺,依循以下顏色過渡:綠色 -> 黃色 -> 紅色 -> 灰色 -> 白色,其中 2800 公尺以上即開始以灰色系展示。這麼高的湖泊,位於一片白色系背景當中,更增添了些許雪國的氣氛 (實際上,的的喀喀湖冬天非常乾燥,幾乎不會下雪\\ [#]_)。 Make a color-coded topographical map of `Lake Titicaca`_ (Lago Titicaca), as the following figure shows. Lake Titicaca is a large lake between Peru and Bolivia with an area of 8372 km\\ :sup:`2`. It’s generally recognized as the highest navigable lake in the world\\ [#]_, with a surface elevation of 3812 m. The blue lines in the figure represent rivers. Note that the river to the right is the upstream of the Amazon River, which does not connect to Lake Titicaca. A blue dashed line illustrates the political border between Peru and Bolivia. The height is color-coded from 0 to 5000 m (following the sequence: green -> yellow -> red -> gray -> white). All elevations above 2800 m are represented in grayish colors. It may give you the impression that the area around Lake Titicaca is the realm of snow since it is immersed in a white background, but in fact, the winter at Lake Titicaca is so dry that it rarely snows a lot\\ [#]_. CC-BY-4.0 +``coast`` - **繪製河流、湖泊與國界** ``coast`` - **plot rivers, lakes, and borders** CC-BY-4.0 +使用 GMT 伺服器的地形資料繪圖 Using the topographic data from the GMT server CC-BY-4.0 +從 `cpt-city`_ 尋找適合地圖的色階檔 Search on `cpt-city`_ for a color ramp that fits your map CC-BY-4.0 +如何疊加輸出圖層 How to overlay multiple layers CC-BY-4.0 +使用腳本、``gmt begin`` 和 ``gmt end``,一次下達所有繪圖指令 Run all of plotting commands in a script at once using ``gmt begin`` and ``gmt end`` CC-BY-4.0 +取得資料 Getting Data CC-BY-4.0 +這次我們必須要先取得繪圖區域的地形資料。GMT 6 本身有提供全球的地形資料,不過是放在遠端伺服器上,當使用者需要時才會下載到本機電腦中。這些地形資料的檔名為: Firstly we have to get the topographic data on our desired plotting region. GMT 6 provides the global topographic data itself stored in a remote server. Those data are only downloaded if needed. The name of the dataset is: CC-BY-4.0 +其中 ``rr`` 是解析度的大小,而 ``u`` 是單位 (有度 ``d``、分 ``m``、秒 ``s`` 可選)。我們在這邊要使用的是全球解析度 1 弧分的地形高程,因此檔名為 ``@earth_relief_01m``。其他可供選擇的資料,皆在 `GMT 官方手冊中有說明 `_。如果你想查閱地形資料的更多資訊,可以透過終端機輸入 ``grdinfo`` 指令來達成。執行畫面會像如下所示: Here ``rr`` is the pixel spacing, and ``u`` is its unit (``d`` for degree, ``m`` for are-minute, and ``s`` for arc-second). We are going to use the global topography in 1 arc-minute, and thus the corresponding dataset name is ``@earth_relief_01m``. `The GMT official manual `_ also tells you how to access other available data. If you want to check your topo data for more information, you can enter ``grdinfo`` in your terminal like what the following panel shows: CC-BY-4.0 +訊息的前兩行在有需要下載時才會出現。下載下來的檔案預設是放在 ``~/.gmt/server/`` 這個位置,之後 GMT 會先查看這個位置有沒有已經下載的檔案,如果沒有的話才會再次下載。下載檔檔名為 ``earth_relief_01m.grd``,副檔名 ``.grd`` 表明了它是某種「網格檔 (grid)」,亦即地球的二維表面被切割成網格狀,每個「格子」內,都有一個相對應的高度數據。(非常類似 GeoTiff 的概念,只不過在 GeoTiff 中,相對應的術語稱為「像素」而非「網格點」。) ``.grd`` 檔是 netCDF 格式常見的附檔名,也就是說它可被 GMT 讀取並作圖。另外,從 ``grdinfo`` 的輸出中你還可以看到其他的基本資訊,像是 The first two lines only appear when it needs to download the data from the server. The downloaded files are stored in ``~/.gmt/server/`` by default. The next time GMT will check if there are already the specified files in this folder and will only download them again if the program cannot find them. You can see that the downloaded file name is ``earth_relief_01m.grd``. The file extension ``.grd`` suggests that it’s a “gridded” file. Imagine part of Earth’s surface is cut like a chessboard, and every cell on this chessboard has one value that represents the height of the surface. This is how a “gridded” surface would look like. (The concept of GeoTiff is similar to this; however, we call each chessboard value a “pixel,” not a “gridded point.”) The extension ``.grd`` is commonly used for netCDF format, which can be loaded and plotted by GMT. From the output text of ``grdinfo`` you can also see CC-BY-4.0 +網格檔是從 `SRTM15+V2 `_ 這個資料庫重新取樣而來。 The gridded data are resampled from a topography database called `SRTM15+V2 `_. CC-BY-4.0 +X 從 -180 度到 180 度,Y 從 -90 度到 90 度,意味著此網格檔涵蓋全球的範圍。 X is from -180 to 180 degrees, and Y is from -90 to 90 degrees. This means the file covers the entire Earth's surface. CC-BY-4.0 +網格大小是 0.0166666666667,也就是 1/60 度 (1 弧分)。 The size of each grid is 0.0166666666667, equal to one sixtieth degrees (1 arc minute). CC-BY-4.0 +總共有 21601 x 10801 = 233312401 個格點 (也就是兩億三千三百萬像素)。 There are in total of 21,601 x 10,801 = 233,312,401 grid points (that is, around one-fourth billion pixels!). CC-BY-4.0 +Z 值 (高度) 從 -10907 到 8170 公尺。為什麼最高的地方不是 8848 公尺 (聖母峰的高度)? 那是因為網格的解析度還是不夠高,1 弧分其實只相當於 1 至 2 公里才取一個點而已。 Z value (height) is from -10907 to 8170 meters. The reason why the highest point is not 8848 m (the elevation of Mt. Everest) is that the resolution of this grid file is not high enough. A 1-arc-minute spacing means we only take one height measurement every 1-2 km. CC-BY-4.0 +從本章開始,我們需要使用兩個以上的 GMT 指令製作地圖。在上一章介紹過的 ``coast`` 用來畫向量式資料 (河流、湖泊以及國界),而在本章中新介紹的 ``grdimage`` 則用來畫地形起伏。因為上一章介紹的 ``-png`` 選項只適用於單一指令,所以在本章我們要用另一種更通用的方式指定輸出檔。具體做法是使用 ``gmt begin`` 和 ``gmt end`` 這兩個關鍵字串把其他所有繪圖指令包起來,像這樣: Starting from this chapter, we will need more than one GMT command to make a map. ``coast`` (introduced in the previous chapter) is for plotting vector data (rivers, lakes, and country borders), and ``grdimage`` (introduced in this chapter) is for plotting topography. In the previous chapter, we introduced the ``-png`` option, but this way is only for single-command mapping. Thus, we will use a more general method to specify the output file in this chapter. It is the use of ``gmt begin`` and ``gmt end`` to wrap all the other plotting commands, like this: CC-BY-4.0 +"$ gmt begin [輸出地圖主檔名,不用加附檔名] [格式] # 輸入後按下 enter +$ [繪圖指令1] # 輸入後按下 enter +$ [繪圖指令2] # 輸入後按下 enter +... +$ gmt end" "$ gmt begin [map name without file extension] [format] # when the command is entered, press enter +$ [plotting command 1] # when the command is entered, press enter +$ [plotting command 2] # when the command is entered, press enter +... +$ gmt end" CC-BY-4.0 +你可以一行一行的在命令列中打好指令再送出執行,不過為了修改方便,我們通常會選擇把所有的指令先寫在\\ :ref:`腳本 <腳本>`\\ 內,再執行此腳本以一次送出所有指令給電腦。在本章中,我們就要來介紹這種更爲便捷的方式。 You can enter these commands line by line and run them separately, but for the convenience of editing, we usually choose to write everything down in a text :ref:`Script`. When you run this script, you send all commands to the computer at once. We will introduce this way by showing how to write a script in this chapter. CC-BY-4.0 +畫地圖的第一步就是決定繪製區域。如同前一章「\\ :doc:`making_first_map`\\ 」所述,我們可以使用 *Google Map* 等工具決定區域。這裡我們考慮到高度的呈現效果,選擇經度從 -70.8 到 -66.56 (負值表示西經),緯度從 -17.17 到 -14.42 (負值表示南緯。) Once we get the global topography data, the next step would be deciding where on the Earth we want to plot (that is, map extent). Like we said in the previous chapter :doc:`making_first_map`, we can use tools like *Google Maps* to determine the region. Here we choose longitude from -70.8 to -66.56 (negative number means W) and latitude from -17.17 to -14.42 (negative number means S), based on the distribution of elevations. CC-BY-4.0 +本次作圖區域在 `Google Map` 上呈現的樣子。 The map extent viewed on `Google Maps`. CC-BY-4.0 +使用 ``grdimage`` 呈現地形數據,最少需要提供兩個參數,分別是 ``輸入檔`` 和 ``-J`` (投影方法和地圖大小)。在這裡我們也需要使用 ``-R`` 指定繪製區域,如果不加 ``-R`` 的話,GMT 會把全網格檔的資料話在地圖上 (因爲我們使用的是全球地形資料,所以輸出會是全球地圖)。就讓我們來畫一張跟\\ `前一章 `_\\ 一樣寬度的地圖吧。請建立新文字檔,檔名可以為 ``titicaca.bash`` 或任何你喜歡、且符合作業系統格式慣例的名字。然後在檔案中輸入: To use ``grdimage`` to plot topography, we need at least two arguments, which are ``input file`` and ``-J`` (projection and map size). We also need ``-R`` (map extent) here since GMT would plot all the gridded data on the map without an ``-R`` setting. (This would be a global map in our case because we are using a global topography dataset.) Let’s make a map with the same size from the map in the `previous chapter `_. Please create a new text file, entitled ``titicaca.bash`` or whatever you like (it’s still better to fit your system format convention). Enter the following lines: CC-BY-4.0 +你會注意到我們在 ``gmt grdimage`` ��面多加了四個空格,這純粹只是製造縮排效果,讓閱讀腳本的人知道這行被包在 ``gmt begin`` 和 ``gmt end`` 之間,增加腳本的可讀性。縮排與否和空格數量不會影響腳本的執行。如需 ``-R`` 與 ``-J`` 選項的語法說明,請至「\\ :doc:`making_first_map`\\ 」中查閱。存檔後,在\\ :ref:`終端機`\\ 模式下前往 ``titicaca.bash`` 所在的資料夾,然後執行腳本 (以 Linux 系統爲例): You may notice that we added four spaces before the ``gmt grdimage`` command. This makes an indentation and lets the readers know that this line is between ``gmt begin`` and ``gmt end`` for readability. The indentation does not affect the script at all. For more information about ``-R`` and ``-J`` options, please go to :doc:`making_first_map`. Save you file, and in the :ref:`Terminal` mode, go to the folder where ``titicaca.bash`` is located and run the script. For example, type this in Linux: CC-BY-4.0 +不同的作業系統的腳本會有不同的額外設定,可以讓你的腳本能夠更方便的執行,詳情請參閱「\\ :doc:`basic_concept`\\」。 If you are running scripts on a platform other than Linux, there will be some extra settings to make the script run more easily. Please see :doc:`basic_concept` for more details. CC-BY-4.0 +輸出的圖檔 ``titicaca.png`` 開啟後應該會是如下的圖案: Open the output file ``titicaca.png`` and you should see a map like this: CC-BY-4.0 +有點難以看懂?這是因為 GMT 預設的套色沒那麼適合這個地區的緣故。在未指定地圖的套色下繪製 ``@earth_relief`` 地形資料時,GMT 會用一套名為 ``geo`` 的色階來呈色。這個色階的顏色如下所示 Hard to comprehend? This is because the default GMT color ramp doesn’t fit this region quite well. If we don’t assign a color ramp for the ``@earth_relief`` topo data, GMT will use one called ``geo`` for the output map. The color distribution of this color scheme is shown here: CC-BY-4.0 +圖中的 ``0`` 和 ``1`` 的顏色,也就是深藍色和白色,會對應到地圖範圍中最低和最高的的地方。有沒有辦法換成另一種比較好看的色階?當然可以,GMT 有數種方法可以製造或調整色階,但這邊我們要先來看一種最簡單的方法:直接下載已經做好的色階來用。 The color of ``0`` and the color of ``1`` -- that is, dark blue and white -- would correspond to the lowest and the highest point on the map. Is there any way to replace it with a better color ramp? Of course, the answer is yes; GMT has several ways to create your color ramp or adjust an existing one, but here we are going to see the simplest method: downloading a ready-to-use color ramp from the Internet. CC-BY-4.0 +`cpt-city`_ 網站蒐集了不少常用的色階,其中也包括 GMT 格式的色階檔。GMT 色階檔通常使用副檔名 ``.cpt``,是 color palette table (色階表) 的縮寫。你可以在網站中搜尋你想要的色階,例如\\ `這個網頁 `_\\ 就列了許多最常被下載的 ``.cpt`` 檔。我們這次來用其中的一個叫做 ``mby`` 的色階看看。按下 ``mby`` 的色階表,你應該就會看到如下頁面 "The website `cpt-city`_ has collected many popular color ramps, including those in the GMT format. GMT-formatted color ramps usually use the file extension ``.cpt``, which represents ""color palette table"". You can look for the color ramp you want on the website; for example, `this page `_ lists the most-downloaded ``.cpt`` files. Here we are going to use the one called ``mby``. Click the ``mby`` color ramp, and you should see the following page:" CC-BY-4.0 +注意圖中的 **-8000 ... 5000**,這是指此色階已經被指定在 -8000 到 5000 公尺之內呈現了。按一下網頁上的 `cpt` 連結就可以把此色階檔下載下來。 Note that the number **-8000 ... 5000** means that this color ramp has been adjusted to illustrate elevations between -8000 and 5000 (meters). Click the link to `cpt` on the page to download this color ramp. CC-BY-4.0 +為了方便起見,\\ :download:`這邊 `\\ 也提供了 ``mby.cpt`` 的下載點。 For your convenience, We also provides the download link to ``mby.cpt`` at :download:`here `. CC-BY-4.0 +使用 ``grdimage`` 中的 ``-C`` 選項,就可以指定要用的色階,只要在 ``-C`` 後接續色階檔檔名就行了。所以我們更新版的腳本為: We can use the ``-C`` option in ``grdimage`` to assign a color ramp in our map -- simply put the name of the ramp file directly after the ``-C`` and you are done. Here's our updated script: CC-BY-4.0 +使用相同的方式再執行一次腳本,這次地圖會變成這樣 Run the script again and your map would become this CC-BY-4.0 +看起來已經有模有樣了。 Looks much better. CC-BY-4.0 +有關於如何自訂色階表,讓地圖的顏色可以隨心���欲變化的技巧,請參閱「\\ :doc:`pen_and_painting`\\ 」與「\\ :doc:`editing_cpt_colorbar`\\ 」。 "If you want to customize your color ramp and use whichever color you like on the map, please see "":doc:`pen_and_painting`"" and "":doc:`editing_cpt_colorbar`.""" CC-BY-4.0 +這個地圖目前有個大問題,就是我們雖然知道地圖中大部份的區域都很高 (灰白色),但是卻看不到我們的主角\\ `的的喀喀湖`_。這是因為地形資料只有記載高度,並沒有記載地表的狀態,所以光靠 ``grdimage`` 是無從得知哪邊是湖泊、海洋等等地貌的。因此,為了標上\\ `的的喀喀湖`_\\ 的位置,我們需要呼叫 ``coast`` 這個指令,利用內建的水體資料幫我們畫上湖泊,順便再畫上邊框。 There is still a big issue on our map. We already know that this whole area is mostly in high altitude (shown in gray-white), but we can't see our primary target `Lake Titicaca`_. This is because the topographic data only contain the heights and don't say anything about the types of land cover. If we only use ``grdimage`` to plot these data, we will not be able to know where the lakes or the seas are. So we have to call ``coast`` in order to mark the location of `Lake Titicaca`_\\ , draw the water body, and put a map frame on it. CC-BY-4.0 +當一張地圖包含兩個以上的作圖指令時,\\ **越上方的圖層要越後畫**。由於我們希望 ``coast`` 畫的湖泊水體疊加在 ``grdimage`` 畫的地形資料上,所以 ``coast`` 指令要排在 ``grdimage`` 之後。再次打開腳本,把內容修改爲: When a map comes from two or more GMT plotting commands, **what lies above should be plotted last**. Since we want the lake from ``coast`` lied above the topo data from ``grdimage``, we have to put the line of ``coast`` command below the ``grdimage`` command. Open the script again and change the content to: CC-BY-4.0 +關於 ``coast`` 的指令解說,請至「\\ :doc:`making_first_map`\\ 」查看。另外,你或許會發現在 ``coast`` 中,沒有 ``-R`` 和 ``-J`` 選項。\\ **當不指定這些選項時,GMT 會自動沿用上次的設定**,也就是 ``grdimage`` 的 ``-R`` 與 ``-J`` 資訊,省下重複輸入相同內容的麻煩。 Please go to :doc:`making_first_map` for using the ``coast`` options. In addition, you may have noticed that there is no ``-R`` and ``-J`` options in ``coast``. **When these options are not specified, GMT automatically follows the settings from the last time**. That is, the settings of ``-R`` and ``-J`` from ``grdimage`` will be used here to save time from entering the same content twice. CC-BY-4.0 +``coast`` 的 ``-S`` 選項會套用在所有水域。如果你的地圖中有海又有湖,而你想分別為海跟湖指定不同顏色,可以試試看換成 ``-C`` 選項。因為本圖沒有海域,``-Scornflowerblue`` 和 ``-Cl/cornflowerblue`` 具有相同效果,不過後者其實只會為湖泊填上顏色。 The ``-S`` option in ``coast`` is for every water body. If there are seas and lakes in your map and you want to assign different colors for each of them, ``-C`` option can do the job for you. There is no ocean area on our map, so ``-Scornflowerblue`` and ``-Cl/cornflowerblue`` have the same effect, although the latter only fills the color into lake areas. CC-BY-4.0 +讓我們看一下 ``coast`` 中的兩個 ``-B`` 選項。實際上它們也可以加在 ``grdimage`` 中,因為邊框屬於哪個圖層在本例中不影響地圖疊加,所以效果會一模一樣。 Let us take a look at two ``-B`` options at ``coast``. Actually, it is also ok to put them in ``grdimage`` because which layer the map frame is plotted on doesn't really matter, and it would look the same. CC-BY-4.0 +在終端機中執行腳本,然後開啟輸出檔,應該會看到下圖: Run the updated script in the terminal and open the output file again. You should see the following map: CC-BY-4.0 +這次總算有個令人滿意的輸出結果。接下來,我們還可以利用 ``coast`` 的其餘功能來美化這張地圖。首先是 ``-I``,它可以幫我們標上河流,語法為 Now, this map is very close to what we want, and the final step is to use other options in ``coast`` to decorate it. First, ``-I`` marks rivers on the map, with the following syntax: CC-BY-4.0 +'-I編號/畫筆' '-Inumber/pen' CC-BY-4.0 +其中的\\ ``編號``\\ 可以為不同的英數字,對應到不同等級的河流;而\\ :ref:`畫筆 <畫筆>`\\ 則用來指定河流的繪圖樣式。這裡我們要使用 ``r`` 這個編號,它對應的是\\ **所有的永久河流**。畫筆樣式則使用 ``0.7p,cornflowerblue``。 The ``number`` is an alphanumerical letter corresponding to different levels of rivers in terms of size, and the :ref:`pen ` is used for giving the appearance of these rivers. Here we use the letter ``r``, corresponding to **all permanent rivers**, and the pen style is ``0.7p,cornflowerblue``. CC-BY-4.0 +另外一個 ``coast`` 的選項是 ``-N``,它可以在地圖上標上政治性的���界。語法同樣為 Another ``coast`` option we are going to use is ``-N`` for plotting political boundaries. Its syntax is similar: CC-BY-4.0 +'-N編號/畫筆' '-Nnumber/pen' CC-BY-4.0 +這裡的\\ ``編號``\\ 一樣可以為不同的英數字,對應到不同等級政治邊界 (國界、州界等)。我們要用的是 ``1``,亦即\\ **標上國界**。至於畫筆樣式,則使用 ``0.7p,,--``,注意這裡我們空下了「顏色」的欄位,因此 GMT 會使用預設值「黑色」進行繪圖。在「線條樣式」欄位中,我們選擇 ``--``,這樣國界就會以虛線呈現。 "The ``number`` here, just like the previous one, is an alphanumerical letter corresponding to different tiers of political boundaries (national, state, etc.). We are going to use ``1``, which means **national boundaries**. We use ``0.7,,--`` for pen attributes; note that we omit the column of ""color,"" so GMT would use the default ""black"" to plot these lines. Also, we choose ``--`` for ""line style"" so that the boundaries will be plotted in dashed lines." CC-BY-4.0 +把 ``-N`` 和 ``-I`` 以及他們的設定參數加入我們的 ``coast`` 指令中,就完成了這次的地圖設計。 Add ``-N`` and ``-I`` and their parameters to our ``coast`` command, and the map design is done. CC-BY-4.0 +「繪製地形設色圖:以 **70.8E - 66.56E,17.17S - 14.42S** 為邊界,麥卡托投影,地圖橫向寬 **6** 吋,套色使用 ``mby.cpt`` 內的色階表。使用 ``cornflowerblue`` 把湖泊和河流上色,畫上國界,四邊繪製邊框與刻度數值,自動選擇數值間隔與刻度間隔,不畫格線,標題為 *Lago Titicaca*,存檔為 ``titicaca.png``。」 """Plot the topographical map -- map extent is set to **(70.8E - 66.56E,17.17S - 14.42S)** in Mercator projection and **6** inches wide. We use the color ramp from ``mby.cpt``, and plot the lake and rivers in ``cornflowerblue``. We also draw national borders, a map frame, and annotation marks on the map, but the locations and the spacing of these marks are automatically determined. We do not plot grid lines this time. The map is entitled *Lago Titicaca* and saved as ``titicaca.png``.""" CC-BY-4.0 +"import pygmt + +# 取得地形資料 +region = [-70.8, -66.56, -17.17, -14.42] +grid = pygmt.datasets.load_earth_relief(resolution='01m', region=region) + +# 繪圖 +fig = pygmt.Figure() +fig.grdimage(grid, region=region, projection='M6i', cmap='mby.cpt') +fig.coast(rivers='r/0.7p,cornflowerblue', borders='1/0.7p,,--', water='cornflowerblue', frame=['af', '+t""Lago Titicaca""']) +fig.show() +fig.savefig('titicaca_pygmt.png')" "import pygmt + +# Get the Earth relief data +region = [-70.8, -66.56, -17.17, -14.42] +grid = pygmt.datasets.load_earth_relief(resolution='01m', region=region) + +# Plotting +fig = pygmt.Figure() +fig.grdimage(grid, region=region, projection='M6i', cmap='mby.cpt') +fig.coast(rivers='r/0.7p,cornflowerblue', borders='1/0.7p,,--', water='cornflowerblue', frame=['af', '+t""Lago Titicaca""']) +fig.show() +fig.savefig('titicaca_pygmt.png')" CC-BY-4.0 +畫出貝加爾湖 (*Lake Baikal* 或 *Baygal nuur*) 與週邊區域的地形設色圖。貝加爾湖是全世界最深的湖泊,也是世界第七大湖,位於俄羅斯,南端接近蒙古的邊界。 Make a colored topographical map of *Lake Baikal* (*Baygal nuur*) and its surrounding area. Lake Baikal is the deepest lake and the seventh-largest lake in the world. It is located in Russia, close to the boundary of Mongolia in the south. CC-BY-4.0 +從地圖中可看到有幾條河流注入或流出貝加爾湖? How many rivers are connected to Lake Baikal? Can you see that on the map? CC-BY-4.0 +貝加爾湖週邊的海拔為何?湖底的海拔為何?你的地圖分別用什麼顏色表示這兩個海拔? How high is the area around Lake Baikal? How high is the bottom of Lake Baikal? What colors are used to represent these two elevations on your map? CC-BY-4.0 +入門與概述 Introduction CC-BY-4.0 +基本繪圖技巧 Beginner Plots CC-BY-4.0 +製作各種常見的地圖(基礎) Making Various Kinds of Maps (Basic) CC-BY-4.0 +製作各種常見的地圖(進階) Making Various Kinds of Maps (Advanced) CC-BY-4.0 +網格資料處理 Processing Gridded Data CC-BY-4.0 +數值資料處理 Statistical Analysis CC-BY-4.0 +附錄與學習資源 Appendices and Learning Resources CC-BY-4.0 +GMT 教學手冊 GMT Tutorials CC-BY-4.0 +**GMT** (**Generic Mapping Tools**, 通常譯成「**通用製圖工具**」) 是一套開放的地理繪圖軟體。與一般的地理繪圖軟體如 QGIS、ArcGIS 最大的不同是,GMT 完全可以在命令列介面底下運行。最新的 PyGMT 軟體更讓 Python 的使用者有更便捷的方式使用 GMT 提供的各種繪圖工具。對於有大量繪圖需求,想用程式語言或腳本批次檔處理這些繪圖工作的人而言,GMT 非常值得一學,但也正因為 GMT 的命令列風格令上手曲線顯得相當陡峭,使得許多想接觸地理繪圖的初學者望之卻步。 **Generic Mapping Tools** (**GMT**) is a set of open-source software for mapping and plotting geographic data. It features a command-line interface, which makes it completely different from the common GIS software like QGIS or ArcGIS. The PyGMT software, which is the latest derivative of GMT, even allows all Python users to use the collection of GMT tools more conveniently. For those who need to deal with a lot of plotting tasks or want to write a script for handling all these jobs, GMT is extremely worth learning. However, The command-line style of GMT syntax would be very challenging and makes the learning curve very steep, especially for beginners who are not familiar with manipulating geographic data and mapping. CC-BY-4.0 +在本教學手冊中,會透過一個個範例介紹 GMT 的基礎知識與許多作圖實用技巧。每個章節的最終目標,基本上都是完成一張精美的插圖,你可以透過這些範例,了解 GMT 許多有用的指令操作方法,以及如何在命令列腳本 (Shell script) 中組織這些指令 (如果是 PyGMT 的話就是在 Python 腳本中組織)。除此之外,本教學也會在適當的地方解說 GMT 如何與 shapefile、GDAL 等相關的格式或軟體銜接,讓您的資料或繪圖處理流程更為順暢。 In these tutorials, we will explore basic knowledge of GMT and useful plotting skills from numerous examples. The goal of each chapter is to produce a high-quality map from scratch and I will show you how to do that step by step. You will be learning many GMT commands and how to organize them in a command-line interface or Shell script (or Python script if using PyGMT). The tutorials will also explain things related to GMT when needed, such as the shapefile data format and the GDAL geospatial software, which would improve the efficiency of your mapping tasks. CC-BY-4.0 +在 2019 年 11 月,GMT 釋出了官方第六版。此版本比起之前大眾常用的 GMT 4 與 GMT 5 改進了不少,而且語法更是全新翻修過。本教學預計以 **GMT 6** 的新式語法為主,但是各章節將附連結至 **GMT 4-5** 的傳統語法供您參考。另外。PyGMT 已於 2020 年發布測試版,因軟體尚在積極開發中,本教學暫時不會詳細的介紹 PyGMT 的各項語法,但是在每一章的最後,你可以找到用 PyGMT 寫成的腳本 (Jupyter Notebook 格式) 來製作此章節的目標圖片。 In November 2019, GMT released its version 6. This version is a major rehaul from the previous GMT 4 and GMT 5, especially for the more concise and easier syntax. In each chapter of this tutorial, we will use the modern syntax introduced by **GMT 6** while providing a link to scripts written in **GMT 4-5** syntax for your reference. In addition, the PyGMT software was released its beta version last year (2020). Since it is under active development, this tutorial does not provide a detailed explanation of its syntax, but instead, you can find a Python script in Jupyter Notebook format at the end of each chapter showing how to make the target chapter figure using PyGMT. CC-BY-4.0 +本教學基本上採循序漸進的模式撰寫,但各篇章使用的材料是互相獨立的。初學者不妨從頭開始閱讀,但如果你已對 GMT 有相當程度的了解,更請隨時跳至你想查閱的部份以節省時間。如果有什麼想分享的評論或使用秘訣,非常歡迎在各章節中留言或直接與[我](mailto:whyjayzheng@gmail.com)聯繫。祝各位都能在閱讀的過程中,享受到使用 GMT 畫地圖的樂趣! The tutorials are designed and written from beginner level to more advanced tricks, but the content in each chapter is actually independent. You can read all the chapters in order if you are a GMT rookie, or you can jump to whichever section you are interested in to save your time if you have been using GMT for a while. Please feel free to leave any messages below any chapters or contact [me](mailto:whyjayzheng@gmail.com) at any time for any questions, comments, and ideas/tips to be shared. I hope you enjoy the fun of mapping from reading these tutorials! CC-BY-4.0 +授權 License CC-BY-4.0 +本著作使用 MIT 與創用 CC 姓名標示 4.0 雙授權,使用者可以依據其想要獲得授權的部份選擇任一或兩個許可: This work is dual-licensed under the MIT and the Creative Commons Attribution 4.0 International licenses. Users can choose either or both licenses according to which part of the work they seek permission: CC-BY-4.0 +[MIT 授權](https://github.com/whyjz/GMT-tutorials/blob/master/LICENSE.md):適用程式碼的部份以及所有的 Jupyter Notebooks。被授權人有權利使用、複製、修改、合併、出版發行、散布、再授權和/或販售軟體及軟體的副本。 [MIT License](https://github.com/whyjz/GMT-tutorials/blob/master/LICENSE.md): For the code and all of the Jupyter Notebooks. Permission is hereby granted, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software. CC-BY-4.0 +[創用 CC 姓名標示 4.0 國際 授權條款](http://creativecommons.org/licenses/by/4.0/):適用於文本部份。在此授權條款下,您可以在任何目的下自由分享或修改本作品,並包含商業性質之使用。您只需給予原作者適當表彰(姓名標示)。 [Creative Commons Attribution 4.0 International License](http://creativecommons.org/licenses/by/4.0/): For the content. You may use, share, or adapt the document in any medium or format for any purpose, even commercially. You must give appropriate credit to the author, provide a link to the license, and indicate if changes were made. CC-BY-4.0 +Copyright © 2016-22 鄭懷傑 (Whyjay Zheng). Copyright © 2016-22 Whyjay Zheng (鄭懷傑). CC-BY-4.0 +教學內文與圖片的原始碼公開在 [Github](https://github.com/whyjz/GMT-tutorials) 上,歡迎隨時動叉! The source codes of all the text and pictures are accessible on [Github](https://github.com/whyjz/GMT-tutorials). Feel free to fork me at any time! CC-BY-4.0 +致謝 Acknowledgments CC-BY-4.0 +感謝 William Durkin,Patricia MacQueen,李明龍,李定宇等人提出的建議與討論,讓本教學手冊的內容更為豐富完整。另外,也感謝所有 Github 上的協作者:譚諤 (tan2),李奎模 (likueimo),王亮 (wangliang1989),對文檔內容所作的建設性修改。在此深深謝謝參與翻譯此教學手冊的人員,翻譯是件龐大的工作,沒有你們的協助是不可能完成的。如您也想參與一起翻譯本教學,請參閱下方說明。 I want to thank William Durkin, Patricia MacQueen, Minlong Lee, and Timothy Ting-Yu Lee for their insightful comments and conversations which have complemented the tutorials. I would also like to thank all the Github contributors, including Er Tan (tan2), KMO Li (likueimo), and Liang Wang (wangliang1989), for their constructive edits to the documentation. Here I give my deep thank-you to all the people who helped translate this work. The translation is a huge amount of work and thus could not have been done without your active support. If you would like to contribute to translating this tutorial, see the next section for more details. CC-BY-4.0 +翻譯協作 Contribute to translation CC-BY-4.0 +如您對翻譯此網站有興趣,歡迎前往在 [Weblate 上公開的專案](https://hosted.weblate.org/engage/gmt-tutorials/)並隨時開始翻譯。感謝您的貢獻! If you are interested in translating this website, please come to the [open project on Weblate](https://hosted.weblate.org/engage/gmt-tutorials/) and start translating at any time. Thank you for contributing to this project! CC-BY-4.0 +贊助本教學 Support this work CC-BY-4.0 +覺得本教學手冊的內容頗有幫助?隨時歡迎[請我喝杯手搖奶茶](https://www.paypal.com/donate?hosted_button_id=68GZNRJ3MZDBE),讓我有更多的能量繼續創作。行有餘力的話,也歡迎出資贊助本教學網站的營運和維護成本 :D Found the content in this tutorial helpful? I'd be grateful if you could [buy me a cup of bubble tea](https://www.paypal.com/donate?hosted_button_id=68GZNRJ3MZDBE) to fuel me up. If you are in a position to help the tutorial thrive, you are welcome to support it for the cost of hosting service :D CC-BY-4.0 +繪製向量式資料 Plot Vector Data CC-BY-4.0 +本教學適用於 GMT 6 的現代模式。如須參閱 GMT 6 (傳統模式) 與 GMT 4-5 繪製相似圖片的教程,\\ `請至這裡 `_。 This instruction is for the Modern Mode in GMT 6. For making the same map using the GMT 6 Classic Mode or GMT 4-5, `Please go to this page `_. CC-BY-4.0 +地理空間資料通常會以網格形式或向量形式儲存。所謂的向量式資料,其實就是描述「點、線、面」位置與形狀的資料。有關於如何繪製點資料的技巧,我們已經在「\\ :doc:`scatter_plot`\\ 」一章中提及,因此在本章中,將會說明如何利用 GMT 繪製線段以及多邊形、簡介與 GMT 相容的向量式資料檔案格式,以及透明度的設定--這種填色技巧非常適合用在常常需要疊在一起呈現的向量式資料上。 Geospatial data are often stored as a raster or a vector format. The so-called vector data describe the locations and the shapes of points, lines, and polygons. We have mentioned how to plot point data in the chapter :doc:`scatter_plot`, and in this chapter we are going to show you how to plot line segments and polygons using GMT. In addition, we will also describe a bit about the GMT-compatible vector file format, and how to set up transparency -- a useful way to illustrate a map with many layers of vector data. CC-BY-4.0 +繪製一張\\ `七巧板 `_\\ 的盤面,如下所示。七巧板是一種類似拼圖的玩具,遊玩目標通常是利用 7 個多邊形拼出指定的圖案。這邊拼出的是正方形,也是所有的圖案裡最基本的一種。 Draw a `tangram `_ like this one. The tangram is a dissection puzzle and your goal is usually to combine all 7 pieces to form the assigned figure. Here the figure is a square, the most basic one among all possible figures. CC-BY-4.0 +在此圖中,七個多邊形顏色均不相同,但都有黑色邊緣,而且在盤面上還有淡色的棋盤式格子,可以幫助你計算每個多邊形的大小。要讓這些線條與多邊形的顏色同時呈現,我們必須要在色階檔中加上透明度的設定,並且使用不同的出圖指令。 In this figure, each polygon piece has a distinct color and a black edge. Also on the figure are pale-gray grid lines that can help to calculate the area of each polygon. To make all of them appear on a single figure, we have to add the transparency settings to the colormap using an additional option for ``makecpt``. CC-BY-4.0 +``makecpt`` - **製作含有透明度設定的離散色階檔** ``makecpt`` - **make a colormap with transparency settings** CC-BY-4.0 +``basemap`` - 設定作圖區的基本資訊 ``basemap`` - set up info of the mapping area CC-BY-4.0 +``plot`` - **繪製線段與多邊形** ``plot`` - **plot segments and polygons** CC-BY-4.0 +在「\\ :doc:`scatter_plot`」中我們看到 ``plot`` 如何處理點資料。如要處理線段資料和多邊形資料,我們可以使用相同的 ``plot`` 語法: In :doc:`scatter_plot`, we have seen how ``plot`` deals with point data. For processing segments and polygons, we can use the same ``plot`` syntax: CC-BY-4.0 +$ gmt plot 輸入檔名稱 [選項...] $ gmt plot input_file [-options] CC-BY-4.0 +線段顧名思義,就是很多個頂點連起來的線條。GMT 接受以純文字格式記載的線段資料,如下所示: As its name suggest, a segment is just a connection between two or more points (vertice). GMT accepts segment data in text (ascii) format as follows: CC-BY-4.0 +"# (所有以 # 號開頭的行都會被解讀成註解) +> [線段 1 的設定] +線段 1 的頂點 1 +線段 1 的頂點 2 +... +> [線段 2 的設定] +線段 2 的頂點 1 +線段 2 的頂點 2 +... +> [線段 3 的設定] +..." "# (all lines starting with \\""#\\"" will be interpreted as comments) +> [settings of segment 1] +segment 1, vertex 1 +segment 1, vertex 2 +... +> [settings of segment 2] +segment 2, vertex 1 +segment 2, vertex 2 +... +> [settings of segment 3] +..." CC-BY-4.0 +如果是二維線段,頂點就是兩欄資料,分別為 X 座標和 Y 座標。因為是線段,所以每條線至少都要有 2 個頂點。不同線段之間預設以 ``>`` 符號隔開,符號後方可以接上 ``-W`` 或者 ``-Z``,代表 ``plot`` 在畫圖時會對這條線使用的繪圖選項: If you are plotting a 2-D segment, your vertices would take 2 columns, which are X and Y coordinates respectively. Every segment must have at least 2 vertices. The ``>`` symbol is used to separate each segment, and after that we can add ``-W`` or ``-Z`` settings in the same line. They indicate the drawing options for the corresponding segment: CC-BY-4.0 +``-W``:指定畫筆樣式 ``-W``: specify pen style CC-BY-4.0 +``-Z``:藉由給定色階檔的數值指定顏色 ``-Z``: specify color by giving a value (which will be later linked to a colormap) CC-BY-4.0 +詳細的說明請參考\\ `這裡 `_。我們就來研究一下,如果要畫出七巧板的背景網格,需要怎麼樣的線段檔案: For detailed information, please go to `this page `_. Now let's take a look at how to design the segment data for the background grid lines on the tangram figure: CC-BY-4.0 +在此檔案中,總共有 6 條線段,前三條是直線,後三條是橫線。以第 1 條為例,它是從座標 (1, 0) 到 (1, 4) 的線段。第一條線段的 ``>`` 符號後面有 ``-W`` 設定,意味著這條線要使用黑色、點點樣式和 3p 寬度來繪製。之後所有的 ``>`` 符號後面都沒有任何設定,當 ``plot`` 在繪圖的時候,會\\ **自動沿用之前已經設定過的參數值**\\ ,因此後五條線畫出來的外觀會與第一條相同。把檔案存為 ``lines.txt``,然後使用如下指令,就可以畫出背景網格。 There are 6 segments in this file; the first three are vertical, and the last three are horizontal. Take the first segment for example, it is a segment from coordinate (1, 0) to (1, 4). To the right of the ``>`` symbol of the first segment, we can see a ``-W`` option, which means this segment would be plotted as a black, dotted, 3-point wide line. There are no options associated with all the other ``>`` symbols. When ``plot`` is reading this file, it would **automatically use the previous value for the next segment**. Hence, all the other segments will use the same line style from this first segment. Save this file as ``lines.txt``, and enter the following command to plot the background grid. CC-BY-4.0 +看起來還不錯!接下來讓我們看一下要怎麼畫多邊形。其實多邊形資料與線段大同小異,就是把所有��頂點座標紀錄在檔案內而已;不過,多邊形的頂點數目最少要有 3 個。GMT 可接受的多邊形檔案格式,如下所示: Looks not bad! Now it's time to deal with the polygons. In fact, the polygon data format is very similar to the segment data since it also records only the vertices in the file. However, you have to have at least three vertice to form a polygon. The GMT-acceptable polygon format is like this: CC-BY-4.0 +"> [多邊形 1 的設定] +多邊形 1 的頂點 1 +多邊形 1 的頂點 2 +多邊形 1 的頂點 3 +... +> [多邊形 2 的設定] +..." "> [settings of polygon 1] +polygon 1 vertex 1 +polygon 1 vertex 2 +polygon 1 vertex 3 +... +> [settings of polygon 2] +..." CC-BY-4.0 +分隔符號後方可以接上 ``-W``、``-Z`` 或 ``-G`` (詳細的說明請參考\\ `這裡 `_\\ ): We can also add ``-W``, ``-Z``, and/or ``-G`` options after the ``>`` symbol (see `this page `_ for details): CC-BY-4.0 +``-W``:指定多邊形的外框畫筆樣式 ``-W``: specify pen style for polygon edges CC-BY-4.0 +``-Z``:藉由給定色階檔的數值指定多邊形填色 ``-Z``: specify a filling color by giving a value (which will be later linked to a colormap) CC-BY-4.0 +``-G``:直接指定多邊形填色 ``-G``: specify a polygon filling color directly CC-BY-4.0 +例如,要畫出七巧板上的圖形,我們可以使用如下的檔案內容: For example, we can use the following content to draw all the polygons in a tangram: CC-BY-4.0 +第一個多邊形是七巧板底部的大三角形,座標從 (0, 0)、(2, 2) 到 (4, 0),各位可以試試看找出其他六個多邊形分別是什麼形狀。注意在每個多邊形的 ``>`` 後方都有 ``-Z`` 設定,代表著我們只要給定色階檔,GMT 就會自動的依照 Z 值與色階檔的對應,為每個多邊形填上不同的顏色。在 GMT 中,有一個稱為「\\ **wysiwyg**\\ [#]_\\ 」的色階檔,最適合用來當這種依照數值指定不同種類顏色的參考色階。它的顏色如下所示: The first polygon is the triangle at the bottom of the tangram. Its vertices are (0, 0), (2, 2), and (4, 0). You can try to figure out what other polygons represent what shape! Note that for each polygon, there is a ``-Z`` setting after ``>``, which means GMT will automatically fill the polygon using this as the value to looking up the color from the colormap. There is a built-in colormap in GMT called **wysiwyg** [#]_, very suitable for categorical filling like this case. Here's its color combination: CC-BY-4.0 +把以上的文字檔案另存成 ``pieces.txt``,然後使用如下的指令繪圖: Save the text as ``pieces.txt`` and make the figure using these commands: CC-BY-4.0 +"gmt begin pieces png + gmt makecpt -Cwysiwyg -T0/20/1 # 色階數值範圍為 0 至 20,每隔 1 取樣 + gmt plot pieces.txt -R0/4/0/4 -JX15c -L -C +gmt end" "gmt begin pieces png + gmt makecpt -Cwysiwyg -T0/20/1 # colormap range is 0 to 20, sampled with an interval of 1 + gmt plot pieces.txt -R0/4/0/4 -JX15c -L -C +gmt end" CC-BY-4.0 +注意這裡的 ``-L``,這個參數會告訴 ``plot`` 我們畫的是多邊形,如此一來 ``plot`` 就會\\ **強制封閉線段**。另外,在畫多邊形的時候,``plot`` 指令的預設行為是畫邊而且不填色。因此,要加上 ``-C`` 告訴 GMT 我們要用新創造的色階檔對多邊形填色。 Note that the ``-L`` option would tell ``plot`` that we are drawing polygons, and then ``plot`` would **close the segments to form polygons**. Also, when plotting polygons the default behavior of ``plot`` command is to draw edges only instead of color filling. Therefore, we need to add ``-C`` telling GMT we are filling these polygons using the newly made colormap. CC-BY-4.0 +這下子七巧板也有模有樣了!我們順便來加上邊框: Now this tangram is really fleshing out! Here we are also adding the edges: CC-BY-4.0 +看起來非常不錯,不過請注意到圖片邊框,線段的寬度似乎跟圖片內部多邊形邊緣線段寬度不一樣。這是因為 GMT 會沿著多邊形的邊緣 (而不是黑色線段的邊緣) 裁剪影像,因此邊框的線段寬度會變成原本的一半。如果你覺得這沒關係,那倒無妨;但如果你是個完美主義者,不想看到不一致的線段寬度,可以選擇的替代方案,就是把多邊形邊框挪到 ``lines.txt`` 裡面做成線段資料,與網格線條一起繪製。因此,我們的 ``lines.txt`` 要多增加幾行資訊: Almost perfect. There is only one little thing: the line at the edge of the figure seems thinner than the edges of the polygons inside the tangram. This is because GMT cuts the image by the edge of the polygons instead of the edge of the black lines; therefore, the edge width would be only half of the original width. If you think this is ok, great; but if you are a perfectionist and don't want to see the lines not consistent in width, here's another way for you: add the polygon edges to ``lines.txt`` as segment data so that they will be plotted with the grid lines. To do this, open ``lines.txt`` and add more lines at the bottom: CC-BY-4.0 +"> -W1p,grey,. +# 注意我改動了網格線段的樣式設定! +1 0 +1 4 +> +2 0 +2 4 +> +3 0 +3 4 +> +0 1 +4 1 +> +0 2 +4 2 +> +0 3 +4 3 +> -W2p,black +0 0 +4 0 +4 4 +0 4 +0 0 +> +0 4 +4 0 +> +0 0 +3 3 +> +3 1 +3 3 +> +1 3 +2 4 +> +2 4 +4 2" "> -W1p,grey,. +# Note tht I changed the style of the grid lines! +1 0 +1 4 +> +2 0 +2 4 +> +3 0 +3 4 +> +0 1 +4 1 +> +0 2 +4 2 +> +0 3 +4 3 +> -W2p,black +0 0 +4 0 +4 4 +0 4 +0 0 +> +0 4 +4 0 +> +0 0 +3 3 +> +3 1 +3 3 +> +1 3 +2 4 +> +2 4 +4 2" CC-BY-4.0 +後半從 ``> -W2p,black`` 開始的部份,就是七巧板邊框與拼圖的邊界線段。讓我們再試一次以下指令: The last half part (starting from ``> -W2p,black``) is the polygon edges in the tangram. Let us retry these commands: CC-BY-4.0 +看起來賞心悅目多了!最後的問題,就是把多邊形和線條疊加在一起而不擋到彼此。這個問題可以簡單的以具有\\ **透明度**\\ 設定的色階解決。``makecpt`` 的 ``-A`` 選項可以用來指定透明度,我們來試著在終端機中輸入: Ok now it looks much better. Our last problem is to add all lines and polygons together on this figure without blocking any of them. We can simply set up a colormap with **transparency** settings and solve this problem. The ``-A`` option of ``makecpt`` is used to specify transparency. Let's enter this on the terminal: CC-BY-4.0 +"$ gmt makecpt -Cwysiwyg -T0/20/1 -A70 # -A: %70 透明 +0 64/0/64@70 1 64/0/64@70 +1 64/0/192@70 2 64/0/192@70 +... (以下略)" "$ gmt makecpt -Cwysiwyg -T0/20/1 -A70 # -A: %70 transparent +0 64/0/64@70 1 64/0/64@70 +1 64/0/192@70 2 64/0/192@70 +... (skipping)" CC-BY-4.0 +在色階資料中,``@`` 符號後面的就是透明度,因此整個顏色的格式為:``紅/綠/藍@透明度``。使用此色階畫圖,所有的顏色就會被套上透明度設定。這下子你就能看到透明、粉嫩粉嫩的顏色了! In the colormap information, the number after ``@`` is the transparency value. The full format of color thus becomes ``R/G/B@Transparency``. Use this colormap for drawing the figure and you will see all the colors being transparently painted. Seems cute, doesn't it? CC-BY-4.0 +本圖片的最終指令稿如下: The final script for the image is: CC-BY-4.0 +"gmt begin tangram_gmt6 png + gmt makecpt -Cwysiwyg -T0/20/1 -A70 + gmt basemap -R0/4/0/4 -JX15c -Bnews # 設定座標軸範圍 (-R) 的同時,不畫出座標軸 (-Bnews) + gmt plot pieces.txt -L -C + gmt plot lines.txt # 先填色再畫邊框,確保邊框會疊在填色上面。你可以試試看把這一行移到更上方,確認透明度的效果設定。 +gmt end" "gmt begin tangram_gmt6 png + gmt makecpt -Cwysiwyg -T0/20/1 -A70 + gmt basemap -R0/4/0/4 -JX15c -Bnews # setting the axis ranges (-R) while not plotting the axes themselves (-Bnews) + gmt plot pieces.txt -L -C + gmt plot lines.txt # filling first and edges later. This makes sure the lines would be on the top, above the filling. You can try to move this line to an earlier place in the script and see what the transparency settings can do. +gmt end" CC-BY-4.0 +線段資料 ``lines.txt`` 內容如下,並\\ :download:`可在這裡下載 `\\ 。 The segment data ``lines.txt`` are as follows, and are available for downloading :download:`here `. CC-BY-4.0 +多邊形資料 ``pieces.txt`` 內容如下,並\\ :download:`可在這裡下載 `\\ 。 The polygon data ``pieces.txt`` are as follows, and are available at :download:`here `. CC-BY-4.0 +「使用 ``wysiwyg`` 作為母色階並加上透明度設定,接下來繪製七巧板填色、座標格線與七巧板邊線。」 """Use ``wysiwyg`` as the master colormap and add transparency settings, and then draw tangram polygons with color filling, grid lines, and the edge of each polygon.""" CC-BY-4.0 +畫出六面體骰子的任一種展開圖,使用 ``wysiwyg`` 作為母色階為每面塗上不同的顏色。 Draw a net of dice (6 faces). Use ``wysiwyg`` to fill each face with a different color. CC-BY-4.0 +What You See Is What You Get, 即「所見即所得」。 What You See Is What You Get. CC-BY-4.0