-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from SWIFTSIM/add_2d_cmaps
Add 2d cmaps
- Loading branch information
Showing
11 changed files
with
574 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
Tools | ||
===== | ||
|
||
:mod:`swiftsimio` includes a few tools to help you make your visualisations | ||
'prettier'. Below we describe these tools and their use. | ||
|
||
2D Color Maps | ||
------------- | ||
|
||
The :mod:`swiftsimio.visualisation.tools.cmaps` module includes three | ||
objects that can be used to deploy two dimensional colour maps. The first, | ||
:class:`swiftsimio.visualisation.tools.cmaps.LinearSegmentedCmap2D`, and second | ||
:class:`swiftsimio.visualisation.tools.cmaps.LinearSegmentedCmap2DHSV`, allow | ||
you to generate new color maps from sets of colors and coordinates. | ||
|
||
.. code-block:: python | ||
bower = LinearSegmentedCmap2D( | ||
colors=[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0], [0.0, 0.0, 0.0]], | ||
coordinates=[[0.0, 0.0], [1.0, 0.0], [0.0, 1.0], [1.0, 1.0]], | ||
name="bower" | ||
) | ||
This generates a color map that is a quasi-linear interpolation between all | ||
of the points. The map can be displayed using the ``plot`` method, | ||
|
||
.. code-block:: python | ||
fig, ax = plt.subplots() | ||
bower.plot(ax) | ||
Which generates: | ||
|
||
.. image:: bower_cmap.png | ||
|
||
Finally, the color map can be applied to data by calling it: | ||
|
||
.. code-block:: python | ||
def vertical_func(x): | ||
return abs(1.0 - 2.0 * x) | ||
def horizontal_func(y): | ||
return y ** 2 | ||
raster_at = np.linspace(0, 1, 1024) | ||
x, y = np.meshgrid(horizontal_func(raster_at), vertical_func(raster_at)) | ||
imaged = bower(x, y) | ||
plt.imsave("test_2d_cmap_output.png", imaged) | ||
Where here ``imaged`` is an RGBA array. This outputs: | ||
|
||
.. image:: test_2d_cmap_output.png | ||
|
||
The final type of 2D color map is loaded from an image, such as the one displayed | ||
below which is similar to the famous color map used for the Millenium simulation. | ||
|
||
.. image:: millenium_cmap.png | ||
|
||
This can be loaded using the | ||
:class:`swiftsimio.visualisation.tools.cmaps.ImageCmap2D` class, as follows: | ||
|
||
.. code-block:: python | ||
mill = ImageCmap2D(filename="millenium_cmap.png") | ||
and can be used similarly to the other color maps. For the example above, this | ||
outputs the following: | ||
|
||
.. image:: test_2d_cmap_output_mill.png | ||
|
||
This is the recommended way to use two dimensional color maps, as their | ||
generation can be quite complex and best left to image-generation programs | ||
such as GIMP or Photoshop. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "4.4.0" | ||
__version__ = "4.5.0" |
Empty file.
Oops, something went wrong.