From ac85a77e317f76ff4fd68505a18656c5d41a6e34 Mon Sep 17 00:00:00 2001 From: sheng09 Date: Fri, 22 Oct 2021 02:12:35 +1100 Subject: [PATCH] This commit is a bug fix, which corrects a bug in the `obspy/imaging/beachball` functions. Specifically, when calling the functions `beach(...)` in `obspy/imaging/mopad_wrapper.py` or `obspy/imaging/beachball.py` with the arguments `axes` not equals `None`, there is always an error if save the plotted beachballs into vector files (e.g., .pdf or .eps). To locate the error/bug, I found that the functions `beach(...)` calls the function `matplotlib.transforms.IdentityTransform()` to create a Transform object. However the created object does not have the method `translate(...)` that is essential for saving plots into vector files. To fix the bug, it is simple by using the function `matplotlib.transforms.Affine2D(np.identity(3))` instead of `matplotlib.transforms.IdentityTransform()` to create the Transform object. The object created by the former has the method `translate(...)` and hence allows for saving into vector files, while the object created by the latter does not. Excep this difference, the objects created by the two functions have the same behaviours. --- obspy/imaging/beachball.py | 2 +- obspy/imaging/mopad_wrapper.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/obspy/imaging/beachball.py b/obspy/imaging/beachball.py index a78be5b34ba..09afacf6708 100644 --- a/obspy/imaging/beachball.py +++ b/obspy/imaging/beachball.py @@ -164,7 +164,7 @@ def beach(fm, linewidth=2, facecolor='b', bgcolor='w', edgecolor='k', # resize. if axes is not None: # This is what holds the aspect ratio (but breaks the positioning) - col.set_transform(transforms.IdentityTransform()) + col.set_transform(transforms.Affine2D(np.identity(3))) # Next is a dirty hack to fix the positioning: # 1. Need to bring the all patches to the origin (0, 0). for p in col._paths: diff --git a/obspy/imaging/mopad_wrapper.py b/obspy/imaging/mopad_wrapper.py index cc52f41a13f..bdb0f7cb423 100644 --- a/obspy/imaging/mopad_wrapper.py +++ b/obspy/imaging/mopad_wrapper.py @@ -192,7 +192,7 @@ def beach(fm, linewidth=2, facecolor='b', bgcolor='w', edgecolor='k', # resize. if axes is not None: # This is what holds the aspect ratio (but breaks the positioning) - collection.set_transform(transforms.IdentityTransform()) + collection.set_transform(transforms.Affine2D(np.identity(3))) # Next is a dirty hack to fix the positioning: # 1. Need to bring the all patches to the origin (0, 0). for p in collection._paths: