-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
NF - Text numeric values for ha and va #1181
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
Conversation
It says "This pull request fails". Not sure what fails. Seems to be some difference in produced figures that is not due to my pull request. Since I do this for the the first time, could anybody have a look and help to track this down? -Alexander |
Based on a very quick look, I don't think the failures have anything to do with your changes. |
Thanks. Maybe some one still wants to do some testing, but it is simple and straight forward enough to see what this does and that is should be OK. The only thing may be if someone wanted to add some extra checks. For example, I only check for numbers using is_numlike(), but is_numlike(np.array([1,1])) also returns true but would make the code fail. I guess I could add to require size() == 1. Should this be done? |
I don't like this idea because of two reasons. It contradicts the idea of being able to anchor text elements in vector output formats #1081. I think the definition of text properties should follow a common consensus that exists throughout various toolkits and formats, and I'm not sure that I've seen this way of text positioning anywhere else yet. Supporting such a definition will make anchoring harder. Also I don't think that this definition is reasonable. Your idea is to have 'some defined distance from a line or symbol'. The distance you'll get however is completely undefined because it will change as the width and height of your text varies. Imagine 2 text elements being placed va=1.1 under a horizontal line. The one with the bigger height will be further away from the line. The canonical way of doing this is to define attributes like margin-left, margin-right, margin-top, margin-bottom. |
OK, I agree you have a good point about the size not being well defined. That would even affect my use case. In some other cases, however, this could be what is desired, say you wanted to align 30% from the bottom for a given text - in this case a fixed 'margin' would not work. So, this solution is not perfect, but it add something w/o removing anything. For the relative size of displacement outside depending of the text string, you would have to take care of this manually. Possible concepts would be size units as in LaTeX 'em'. But just points would seem ideal to me. Then the question is whether to measure w/r the base line or the top. Even the current implementation with 'top' aliment - it I used it on 'o' or 'O', say both below a given horizontal line, they would have different base lines and that would look ugly. So you would want to have a 'font upper bound' for use instead? BTW, I don't see any 'margin' in the Text definition, is there? Hmm, relative alignment with the text, i.e., 0...1, may still be useful? For distances along the 'margin' idea one would have to agree on a unit - I recommend points to be consistent with symbol size definitions - and a reference point. Not sure how to get these, though. Default could be 'baseline', but 'top' and 'bottom', maybe 'center' could be useful as well. I does require extra parameters - horizontal_offset and vertical_offset relative to the reference point. Would that be a better solution? And most of all, an acceptable solution? (I do need a solution, the current fix may be too simple, but at least gets one part-ways there, so it could be added until some one has a better one, or we agree on a better one, I am happy to work on it if there is an agreement what to do.) -Alexander |
OK, I still think keeping the numerical number as implemented can be useful to allow flexible anchoring relative to the actual size of the text, not just 'top', 'bottom', etc. I agree with pwuertz something else needs to be done. Not sure the margin-x would work as it leaves open the question of aliment. Unless margin-* implies alignment w/r that same, which could be confusing. I propose to keep the ha/va, add the numeric values as I have done, and then add an 'offset' keyword (horizonatloffset/ho and verticaloffset/vo). The question is the units. It should be a fixed unit w/r the font, e.g., points (as is also used for marker sizes - which is the purpose of the exercise to have fond at a fixed distance from the boundary of a marker symbol. So, in my case I could have x,y= 0.5,0.5 (vo is to be added) |
... another possible scale other than point could be font size from prop.get_size_in_points() |
it would just seem a straight-forward addition that does not interfere with I don't understand why this is an issue? I got very frustrated about adding things to matplotlib. On Wed, Nov 27, 2013 at 4:47 AM, Thomas A Caswell
|
@2sn I am sorry you feel that way. It is not clear that this change does not interfere with anything, as @pwuertz says that this complicates dealing with text in vector backends. Due to the complication in properly laying out text it also makes sense to keep mpl's interface as close to the 'standard' properties interface as possible. I have also never seen text alignment specified this way. You agreed that, as written, this has undefined behavior and would need to be modified. You suggested some alternates in the comments, but they did not go into the repo. After a year of no activity I assumed this was dead. I would also suggest that there are alternate (and easier) ways to do what you want. The example usage you gave in your 3rd to last comment can be done with
I think in most cases where you would want to use this functionality you would be better off moving the (x, y) location of the string. |
I was about to say the exact same thing, thanks to @tacaswell I dont have to :). |
@2sn - I just wanted to encourage you to continue making submissions to matplotlib. Matplotlib is a complex tool which no one person can know everything about (even @mdboom and the late, great @jdh2358). As such it is inevitable that for some PRs it will transpire that the change makes a certain facet harder or even impossible to maintain, as I believe was the case with this proposed change. Whilst I'm the first to admit that we are pretty slow at actually getting PRs merged (the order of several months is not unheard of), it is, IMHO, fairly rare that a proposed change doesn't actually make it into mpl in some form or another, and I can assure you that the diversity of contributors to matplotlib is one of the main reasons I love being involved with the project. As I say, please don't be discouraged from discussing changes on the mailing list, or indeed submitting PRs - we are just trying to balance improving usability and functionality of matplotlib whilst still keeping it on the straight-and-narrow in a maintainable and extendible form. Thanks to @tacaswell & @pwuertz for giving an honest and clear description of why this PR was rejected. Cheers, |
…density is now referred to as gaussian_kde and exists as a class in mlab. Updated violinplot examples with up-to-date customization options
…density is now referred to as gaussian_kde and exists as a class in mlab. Fixed list comp position bug and updated examples
…density is now referred to as gaussian_kde and exists as a class in mlab. Fixed list comp position bug and updated examples
…density is now referred to as gaussian_kde and exists as a class in mlab. Fixed list comp position bug and updated examples
…density is now referred to as gaussian_kde and exists as a class in mlab. Fixed list comp position bug and updated examples
…density is now referred to as gaussian_kde and exists as a class in mlab. Fixed list comp position bug and updated examples
…density is now referred to as gaussian_kde and exists as a class in mlab. Fixed list comp position bug and updated examples
Can this be resurrected? I can update (rebase/cherry-pick for proper attribution) it if possible. Functionally, the strings 'left', 'right', 'top', 'bottom' and 'center' represent multiplicative factors. If the underlying factors are made available users may find it an acceptable solution whether a better For precedence, However This is a good example. Also the last graph here is another example where because of the type of plot it was easier to fiddle with These use cases would be very handy if available in ggplot for python which hinges on this PR. |
Dear Hassan, I use the alignment in graphs where the font has to be plotted relative Obviously, it is a rather small change to the class. Best wishes, On 06/09/15 11:58, Hassan Kibirige wrote:
|
The underlying problem of how to correctly deal with this is vector outputs still remains and, @mdehoon can correct me, I suspect that implementing this in OSX would be non-trivial. I think you can achieve the effect you want using In the SO link, they are just cycling between In the weather plot it looks like the |
Hi,
I added a quick patch to allow numerical values for text alignment.
It now allows a number that is fraction of text hight or with and is measured relative to bottom or left. So
ha = 0 == 'left'
ha = 1 == 'right'
va = 0 == 'bottom'
va = 1 == 'top'
va/ha = 0.5 == 'center'
the cool thing is that values outside [0,1] allow you to some defined distance from a line or symbol that remains well-measured even if you interactively scale the figure.
Can you please add this to MPL?
(also fixed some typos in typo doc)
OK, I try this pull request, I hope this is OK and I don't bother not too many people by maybe doing this somewhat out of line.
-Alexander