<jupyter_start><jupyter_text>Plotting data pointsThis tutorial will show you how to plot data points with GMT/Python.Start by importing the `gmt` Python package:<jupyter_code>import gmt<jupyter_output><empty_output><jupyter_text>Cartesian plotsThe `gmt.Figure` class has a `plot` method for displaying points and lines. Let's make a Cartesian x, y plot using some random data generated using numpy:<jupyter_code>import numpy as np
# See the random number generator so we always 
# get the same numbers
np.random.seed(42)
ndata = 100
region = [150, 240, -10, 60]
# Create some fake distribution of points and a measured value
x = np.random.uniform(region[0], region[1], ndata)
y = np.random.uniform(region[2], region[3], ndata)
magnitude = np.random.uniform(1, 5, size=ndata)<jupyter_output><empty_output><jupyter_text>Now we can plot the data using `Figure.plot` and the Cartesian projection `X`.<jupyter_code>fig = gmt.Figure()
# Create a 6x6 inch basemap using the data region
fig.basemap(region=region, projection='X6i', frame=True)
# Plot using triangles (i) of 0.3 cm
fig.plot(x, y, style='i0.3c', color='black')
fig.show()<jupyter_output><empty_output><jupyter_text>We can make the size of the markers follow the fake "magnitude" values by passing in the argument `sizes` to `Figure.plot`. We'll need to scale the magnitude so that it will reflect the size in centimeters.<jupyter_code>fig = gmt.Figure()
fig.basemap(region=region, projection='X6i', frame=True)
fig.plot(x, y, style='ic', color='black', sizes=magnitude/10)
fig.show()<jupyter_output><empty_output><jupyter_text>Plotting directly from a fileSometimes you'll have data in a file that you just want to plot without having to load it into Python. You can use the `data` argument of `Figure.plot` to specify the file name instead `x` and `y`. GMT will take care of loading your data and plotting.<jupyter_code># Save our fake data to a file.
np.savetxt('first-steps-data.txt', 
           np.transpose([x, y, magnitude]))<jupyter_output><empty_output><jupyter_text>The `columns` argument controls which columns are used as x, y, color, and size, respectively. GMT allows some basic operations on the column values before plotting. For example, adding `sVALUE` to a column index will multiply it by that value before plotting.<jupyter_code>fig = gmt.Figure()
fig.basemap(region=region, projection='X6i', frame=True)
fig.plot(data='first-steps-data.txt', style='cc', color='red', 
         columns=[0, 1, '2s0.1'])
fig.show()<jupyter_output><empty_output><jupyter_text>Making maps using sample dataGMT shines when plotting data on a map. We can use some **sample data** that is packaged with GMT to try this out. They can be accessed using special file names that begin with an `@` symbol, for example `@tut_quakes.ngdc`. You can supply these names as the `data` argument in `Figure.plot` and other plotting functions. If you don't have the files already, they are automatically downloaded by GMT and saved to a cache directory (usually `~/.gmt/cache`).The `gmt.datasets` package allows easy access to these data files as Python data types. For example, we can access the sample dataset of tsunami generating earthquakes around Japan (`@tut_quakes.ngdc`) as a `pandas.DataFrame` using the `datasets.load_japan_quakes` function:<jupyter_code>from gmt.datasets import load_japan_quakes

quakes = load_japan_quakes()
quakes.head()<jupyter_output><empty_output><jupyter_text>The functions returns to us the data in a `pandas.Dataframe` object that contains the date, hypocenter coordinates, and magnitude of the earthquakes.Let's make a local Mercator map of the epicenter coordinates.<jupyter_code>quakes_region = [quakes.longitude.min() - 1, quakes.longitude.max() + 1,
                 quakes.latitude.min() - 1, quakes.latitude.max() + 1]
fig = gmt.Figure()
fig.coast(region=quakes_region, projection='M6i', frame=True, 
          land='black', water='skyblue')
fig.plot(x=quakes.longitude, y=quakes.latitude, 
         style='c0.3c', color='white', pen='black')
fig.show()<jupyter_output><empty_output><jupyter_text>As before, we can map the size of the markers to the earthquake magnitude. Because the magnitude is on a logarithmic scale, it helps to show the differences by scaling the values using a power law.<jupyter_code>fig = gmt.Figure()
fig.coast(region=quakes_region, projection='M6i', frame=True, 
          land='black', water='skyblue')
fig.plot(x=quakes.longitude, y=quakes.latitude, 
         sizes=0.02*(2**quakes.magnitude),
         style='cc', color='white', pen='black')
fig.show()<jupyter_output><empty_output><jupyter_text>We can also map the colors of the markers to the depths by passing an array to the `color` argument and providing a colormap name (`cmap`). We can even use the new matplotlib colormap `"viridis"`.<jupyter_code>fig = gmt.Figure()
fig.coast(region=quakes_region, projection='M6i', frame=True, 
          land='black', water='skyblue')
fig.plot(x=quakes.longitude, y=quakes.latitude, 
         sizes=0.02*2**quakes.magnitude,
         color=quakes.depth_km/quakes.depth_km.max(),
         cmap='viridis', style='cc', pen='black')
fig.show()<jupyter_output><empty_output><jupyter_text>Interactive map previews Let's preview this map using the **interactive globe**. In this case, we don't need the frame or color in the oceans. We must also use a **Cartesian projection** (X) and degrees (d) for plot units so that the figure can be aligned with the globe.<jupyter_code>fig = gmt.Figure()
fig.coast(region=quakes_region, projection='X6id/6id', land='gray')
fig.plot(x=quakes.longitude, y=quakes.latitude, 
         sizes=0.02*2**quakes.magnitude,
         color=quakes.depth_km/quakes.depth_km.max(),
         cmap='viridis', style='cc', pen='black')
fig.show(method='globe')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1137106485463616, 'fraction_numerical': 0.010321692757612248, 'mean_word_length': 5.3058568329718, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '649181', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1917, 'n_tokens_neox': 1830, 'n_words': 612, 'path': 'doc/tutorials/plot-data-points.ipynb', 'repo_name': 'btozer/gmt-python', 'size': '5813'}