Skip to content

Change test_makecpt.py to use colorbar instead of grdimage #1748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 26, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pygmt/tests/baseline/test_makecpt_categorical.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
outs:
- md5: 9a8c5ecec5f8962987635057f577a01c
size: 6029
- md5: 2b3f8b4df74b84bd3efd8e765e90c85a
size: 10001
path: test_makecpt_categorical.png
4 changes: 2 additions & 2 deletions pygmt/tests/baseline/test_makecpt_continuous.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
outs:
- md5: 9a18c81caa92725aa9de5c2dd7d74e46
size: 75856
- md5: 2f4698af7229ab7ed717bf0e58cc2500
size: 6816
path: test_makecpt_continuous.png
4 changes: 2 additions & 2 deletions pygmt/tests/baseline/test_makecpt_cyclic.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
outs:
- md5: 4ad410eb2843b3b47818121563c79254
size: 4628
- md5: b9a7c3d47ad47d8ddeb3ed4ba30a0cc8
size: 8158
path: test_makecpt_cyclic.png
4 changes: 2 additions & 2 deletions pygmt/tests/baseline/test_makecpt_plot_grid.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
outs:
- md5: 690415b96990c3b1d1388bf263e40a0d
size: 150867
- md5: 0cb93a6ee8a76e3723236185afaea0cf
size: 7199
path: test_makecpt_plot_grid.png
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
outs:
- md5: aea39948ca2ea6924618a0e09b0020b3
size: 118302
- md5: a4578c19a22e72f0a34cfa96fbefae63
size: 7562
path: test_makecpt_plot_grid_scaled_with_series.png
2 changes: 1 addition & 1 deletion pygmt/tests/baseline/test_makecpt_plot_points.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
outs:
- md5: b28ff0dad316d0b6a860b8af7e402a56
- md5: 7944289487b6efd9755a931e371d8022
size: 26601
path: test_makecpt_plot_points.png
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
outs:
- md5: 6a5ca01aebcc23b00dc884fcd9c927d8
size: 141567
- md5: 96f03f2db80f940addc153e16fb2c7c6
size: 7957
path: test_makecpt_reverse_color_and_zsign.png
4 changes: 2 additions & 2 deletions pygmt/tests/baseline/test_makecpt_reverse_color_only.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
outs:
- md5: 5ad9b6aab72e45be8a1adc20f9e1c0e9
size: 71377
- md5: 900279bd3d608c31e51b6aa83fb486ef
size: 8845
path: test_makecpt_reverse_color_only.png
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
outs:
- md5: 26f3d0d95a68799ddd4eb8a130bc1445
size: 97790
- md5: c755e6ee5fcc399918822c2595cdde8d
size: 7762
path: test_makecpt_truncated_zlow_zhigh.png
51 changes: 25 additions & 26 deletions pygmt/tests/test_makecpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import numpy as np
import pytest
from pygmt import Figure, makecpt
from pygmt.datasets import load_earth_relief
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import GMTTempFile

Expand All @@ -30,12 +29,12 @@ def fixture_region():
return [10, 70, -5, 10]


@pytest.fixture(scope="module", name="grid")
def fixture_grid():
@pytest.fixture(scope="module", name="position")
def fixture_position():
"""
Load the grid data from the sample earth_relief file.
Return the standard argument for the position argument.
"""
return load_earth_relief(registration="gridline")
return "x0c/0c+w10c"


@pytest.mark.mpl_image_compare
Expand All @@ -57,25 +56,25 @@ def test_makecpt_plot_points(points, region):


@pytest.mark.mpl_image_compare
def test_makecpt_plot_grid(grid):
def test_makecpt_plot_grid(position):
"""
Use static color palette table to change color of grid.
"""
fig = Figure()
makecpt(cmap="relief")
fig.grdimage(grid, projection="W0/10c")
fig.colorbar(cmap=True, frame=True, position=position)
return fig


@pytest.mark.mpl_image_compare
def test_makecpt_plot_grid_scaled_with_series(grid):
def test_makecpt_plot_grid_scaled_with_series(position):
"""
Use static color palette table scaled to a min/max series to change color
of grid.
"""
fig = Figure()
makecpt(cmap="oleron", series=[-4500, 4500])
fig.grdimage(grid, projection="W0/10c")
makecpt(cmap="oleron", series=[0, 1000])
fig.colorbar(cmap=True, frame=True, position=position)
return fig


Expand Down Expand Up @@ -105,70 +104,70 @@ def test_makecpt_invalid_output():


@pytest.mark.mpl_image_compare
def test_makecpt_truncated_zlow_zhigh(grid):
def test_makecpt_truncated_zlow_zhigh(position):
"""
Use static color palette table that is truncated to z-low and z-high.
"""
fig = Figure()
makecpt(cmap="rainbow", truncate=[0.15, 0.85], series=[-4500, 4500])
fig.grdimage(grid, projection="W0/10c")
makecpt(cmap="rainbow", truncate=[0.15, 0.85], series=[0, 1000])
fig.colorbar(cmap=True, frame=True, position=position)
return fig


@pytest.mark.mpl_image_compare
def test_makecpt_reverse_color_only(grid):
def test_makecpt_reverse_color_only(position):
"""
Use static color palette table with its colors reversed.
"""
fig = Figure()
makecpt(cmap="earth", reverse=True)
fig.grdimage(grid, projection="W0/10c")
makecpt(cmap="earth", reverse=True, series=[0, 1000])
fig.colorbar(cmap=True, frame=True, position=position)
return fig


@pytest.mark.mpl_image_compare
def test_makecpt_reverse_color_and_zsign(grid):
def test_makecpt_reverse_color_and_zsign(position):
"""
Use static color palette table with both its colors and z-value sign
reversed.
"""
fig = Figure()
makecpt(cmap="earth", reverse="cz")
fig.grdimage(grid, projection="W0/10c")
makecpt(cmap="earth", reverse="cz", series=[0, 1000])
fig.colorbar(cmap=True, frame=True, position=position)
return fig


@pytest.mark.mpl_image_compare
def test_makecpt_continuous(grid):
def test_makecpt_continuous(position):
"""
Use static color palette table that is continuous from blue to white and
scaled from -4500 to 4500m.
"""
fig = Figure()
makecpt(cmap="blue,white", continuous=True, series=[-4500, 4500])
fig.grdimage(grid, projection="W0/10c")
makecpt(cmap="blue,white", continuous=True, series=[0, 1000])
fig.colorbar(cmap=True, frame=True, position=position)
return fig


@pytest.mark.mpl_image_compare
def test_makecpt_categorical(region):
def test_makecpt_categorical(position):
"""
Use static color palette table that is categorical.
"""
fig = Figure()
makecpt(cmap="categorical", categorical=True)
fig.colorbar(cmap=True, region=region, frame=True, position="JBC")
fig.colorbar(cmap=True, frame=True, position=position)
return fig


@pytest.mark.mpl_image_compare
def test_makecpt_cyclic(region):
def test_makecpt_cyclic(position):
"""
Use static color palette table that is cyclic.
"""
fig = Figure()
makecpt(cmap="cork", cyclic=True)
fig.colorbar(cmap=True, region=region, frame=True, position="JBC")
fig.colorbar(cmap=True, frame=True, position=position)
return fig


Expand Down