Skip to content

Add a dpi transform to AuxTransformBox #7344

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

Closed
wants to merge 1 commit into from

Conversation

has2k1
Copy link
Contributor

@has2k1 has2k1 commented Oct 25, 2016

Issue
While the children themselves (e.g. Text objects) of an AuxTransformBox
do conform to the dpi of the figure, the locations of the objects
do not. Therefore the space taken up by the AuxTransformBox remains
just about fixed, regardless of dpi. The relative distance between
any two objects in the AuxTransformBox remains absolutely fixed. This
leads to "scaling" artefacts for png output when the dpi is not 72.

Solution
Add a similar dpi transformation to that done for the DrawingArea.

@has2k1 has2k1 force-pushed the fix-auxtransformbox-dpi branch 3 times, most recently from 136f895 to ddf6d95 Compare October 26, 2016 10:59
@has2k1
Copy link
Contributor Author

has2k1 commented Oct 26, 2016

Please wait on considering this PR.

@tacaswell
Copy link
Member

That looks like it fixes a pretty major bug!

@tacaswell tacaswell added this to the 2.0.1 (next bug fix release) milestone Oct 27, 2016
Copy link
Contributor

@dopplershift dopplershift left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor pep8 nit. Otherwise, I think this looks good.

@@ -963,13 +966,18 @@ def get_extent(self, renderer):
mtx = self.offset_transform.matrix_from_values(*_off)
self.offset_transform.set_matrix(mtx)

return ub.width, ub.height, 0., 0.
dpi_cor = renderer.points_to_pixels(1.)
return ub.width*dpi_cor, ub.height*dpi_cor, 0., 0.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: need spaces around * for pep8.

Copy link
Contributor Author

@has2k1 has2k1 Oct 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think pep8 is fine with that for arithmetic operators, it calls for consistency, readability/good judgment. Either way, when I make a revision to the PR that line will not be there(for a yet unknown reason).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pep8 is fine with that. Both the document and the tool.

@efiring
Copy link
Member

efiring commented Oct 27, 2016

On 2016/10/27 1:17 PM, Hassan Kibirige wrote:

I think pep8 is fine with that for arithmetic operators, it calls for
consistency, readability/good judgment.

The actual PEP 8 does, exactly as you say--but the automated checker
does not. Contrary to the letter and the spirit of PEP 8, the automated
checking regime is a strict application of rules. No judgment is
allowed. It has its advantages in yielding consistency, but it can be
annoying.

(Sorry, I couldn't resist the digression.)

@has2k1
Copy link
Contributor Author

has2k1 commented Oct 27, 2016

@efiring, thanks for the digression I prefer the automated solution and you have put question marks around the efficacy of the tools I use. According the .travis.yml the automated checker is the pep8 package, the same thing I use for my editor. Also the manual invocation of which

pep8 lib/matplotlib/offsetbox.py | grep 970

yields nothing.

@dopplershift
Copy link
Contributor

Because of course the automatic tool and the document can't be in agreement. On the plus side, I learned more about the actual document today.

@NelleV
Copy link
Member

NelleV commented Oct 28, 2016

@dopplershift The tool and the document are on agreement on that particular point.

@dopplershift
Copy link
Contributor

I swear I've seen it error on that--apparently I'm wrong.

@NelleV
Copy link
Member

NelleV commented Oct 28, 2016

You are not wrong. Just outdated :-D
That particular point was fixed in a release of pep8 late 2012/early 2013

@efiring
Copy link
Member

efiring commented Oct 28, 2016

That's good to know--it's a big improvement. I think that (a*b + c*d) is often more readable than (a * b + c * d).

@NelleV
Copy link
Member

NelleV commented Oct 28, 2016

If we want to be more reliable on enforcing pep8 on new patches, we could run flake8 on the diff of the patch instead of how we currently run pep8 (which only looks at whether the number of pep8 violations is lower or equal than the previous patch). Some projects do that (joblib, scikit-learn and maybe ipython/jupyter folks). It should be quite easy to set up.

@NelleV
Copy link
Member

NelleV commented Oct 28, 2016

@has2k1 Do you mind explaining why we should wait on considering this PR?

@NelleV NelleV changed the title Add a dpi transform to AuxTransformBox [MRG+1] Add a dpi transform to AuxTransformBox Oct 28, 2016
@NelleV NelleV added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Oct 28, 2016
NelleV
NelleV previously approved these changes Oct 28, 2016
@dopplershift dopplershift dismissed their stale review October 28, 2016 21:05

Apparently I don't understand pep8. 😁

@has2k1
Copy link
Contributor Author

has2k1 commented Oct 28, 2016

@NelleV, The solution so far does not completely solve the problem, as straight forward as it may be! A slight (and not good looking) modification though yields better results but it is not stable. I will put up a more complete illustration that should aid in getting better help.

@NelleV NelleV dismissed their stale review October 29, 2016 00:32

Because @has2k1 has a better fix in the pipeline :D

@NelleV NelleV changed the title [MRG+1] Add a dpi transform to AuxTransformBox Add a dpi transform to AuxTransformBox Oct 29, 2016
@NelleV NelleV modified the milestones: 2.0 (style change major release), 2.0.1 (next bug fix release) Oct 31, 2016
@NelleV
Copy link
Member

NelleV commented Nov 8, 2016

Hi @has2k1
I know you have a better fix in the pipeline, but do you mind if we merge this in the mean time? The current patch does fix a major bug in matplotlib, and I think that having an approximate fix is much better than no fix at all.
Thanks,
N

@has2k1
Copy link
Contributor Author

has2k1 commented Nov 8, 2016

@NelleV, hold on for a day. I'll push update and a dump of my worksheet that shows the limitations.

**Issue**
While the children themselves (e.g. Text objects) to an AuxTransformBox
do conform to the dpi of the figure, the locations of the objects
do not. Therefore the space taken up by the AuxTransformBox remains
just about fixed, regardless of dpi. The relative distance between
any two objects in the AuxTransformBox remains absolutely fixed. This
leads to "scaling" artefacts for *png* output when the dpi is not 72.

**Solution**
Add a similar dpi transformation to that done for the DrawingArea.
@QuLogic
Copy link
Member

QuLogic commented Nov 13, 2016

Try enabling the frame on the AnchoredSizeBar and see if you can figure out where it really is now.

@has2k1
Copy link
Contributor Author

has2k1 commented Nov 13, 2016

I did that. It is at the bottom. Some of it below the x-axis.

@has2k1
Copy link
Contributor Author

has2k1 commented Nov 17, 2016

My previous response was facilitated by a poor memory. This is the result.
test-144dpi

The problem is that for the AnchoredSizeBar the AuxTransformBox is created with transform=ax.transData. If you used an IdentityTransform as is the case for the red boxes, then it works.

@efiring
Copy link
Member

efiring commented Nov 25, 2016

Is this ready to go after a rebase? Or are there still problems with it? If so, is it really release-critical?

@QuLogic
Copy link
Member

QuLogic commented Nov 26, 2016

I don't think this is one rebase away from being ready; there's still the question of what to do with AnchoredSizeBar. I've convinced myself that it is working correctly, so something will have to be done to ensure it works the same way once this PR is okay.

You'll have to ask @NelleV why it's release critical.

@has2k1
Copy link
Contributor Author

has2k1 commented Nov 27, 2016

I am in agreement with @QuLogic. I have without success tried to find a fix for AnchoredsizeBar.

@NelleV
Copy link
Member

NelleV commented Nov 28, 2016

We can remove the release critical label, but this is a major bug. All the publications that use this are wrong, and we are probably talking thousands of publications.

@QuLogic
Copy link
Member

QuLogic commented Nov 28, 2016

I'm not so sure it's that major. AuxTransformBox is not used anywhere in matplotlib proper. It is used in axes_grid1.anchored_artists.{AnchoredAuxTransformBox,AnchoredEllipse,AnchoredSizeBar} and provided as an alias in axes_grid1.anchored_artists. In the former case, the documentation suggests using something like ax.transData as the transform, which includes DPI automatically. AuxTransformBox itself is not really well documented.

This bug only arises when using AuxTransformBox with IdentityTransform, which by definition does not include a DPI adjustment, and it only affects text because fonts are always specified in points which do obey DPI. So is it really a bug, or is just an unfortunate combination of many factors? Are there actually a whole lot of publications using AuxTransformBox in this manner, or do they use one of the wrappers, which seem to work fine if used as documented?

@QuLogic
Copy link
Member

QuLogic commented Dec 7, 2016

I'm un-critical-izing this as I don't think it will be fixed soon and I'm not so sure it's that critical.

@QuLogic QuLogic removed the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Dec 7, 2016
@QuLogic QuLogic modified the milestones: 2.0.1 (next bug fix release), 2.0 (style change major release) Dec 7, 2016
has2k1 added a commit to has2k1/plotnine that referenced this pull request Apr 25, 2017
When the dpi is not 72, the legend text of the `colorbar` does
not align with the ticks. The patch works for our case but has
other complications, as a result it is not merged in Matplotlib.

See: matplotlib/matplotlib#7344
@QuLogic QuLogic modified the milestones: 2.0.1 (next bug fix release), 2.0.2 (next bug fix release) May 3, 2017
@tacaswell tacaswell modified the milestones: 2.1.1 (next bug fix release), 2.2 (next feature release) Oct 9, 2017
@jklymak
Copy link
Member

jklymak commented Sep 12, 2020

I'm pretty confused if this really needs to be fixed or just closed. Hopefully one of the original proponents can chime in again? Otherwise I've marked stale and will close in a month or so.

@has2k1
Copy link
Contributor Author

has2k1 commented Sep 12, 2020

As I recall, it is not easy fix to this issue without breaking AnchoredSizeBar which relies on the "bug". If we should fix it, we can create a special (internal) subclass of AuxTransformBox that is used by AnchoredSizeBar so that it is not broken by the solution!

For my use case in Plotnine, I created a AuxTransformBox subclass that worked as I expected.

@jklymak jklymak marked this pull request as draft September 12, 2020 21:22
@jklymak
Copy link
Member

jklymak commented Sep 12, 2020

I don't at all mind this going forward... I've just moved to draft, and feel free to update or start again if you are interested. I'm just cleaning up and haven't thought about it deeply.

@jklymak
Copy link
Member

jklymak commented Jun 14, 2021

I'll close as abandoned here.

@jklymak jklymak closed this Jun 14, 2021
@story645 story645 removed this from the future releases milestone Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants