Skip to content
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

Format ticks for non-SI-unit axis in a more readable way #1243

Merged

Conversation

Dominik-Vogel
Copy link
Contributor

@Dominik-Vogel Dominik-Vogel commented Aug 23, 2018

With @astafan8 fantastic PR #1239 the axis in plot_by_id are scaled just like it was the case for the old dataset.
This PR fixes the case of unit less axis, that has not been touched in the named PR. With this PR these get scaled and displayed in the same way as all others.
@nataliejpg

Copy link
Contributor

@astafan8 astafan8 left a comment

Choose a reason for hiding this comment

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

Just to clarify, for unit-less data, do users also want to get kilo/micro/femto stuff in the labels? If so, then this commit is not enough. If no, then I'm confused about what is going on.

In any case, don't forget to:

  • update the tests (see travis)
  • update docstrings in plotting.py file to reflect that something else happens in case of unit-less data
  • perhaps, update the example notebook (most probably "offline plotting tutorial")

@WilliamHPNielsen
Copy link
Contributor

I am also confused 😃
The else clause is not specifically for unit-less values, but for anything not in _UNITS_FOR_RESCALING (famous example: e^2/hbar). Why does that situation call for a not-None ticks_formatter?

@Dominik-Vogel
Copy link
Contributor Author

Dominik-Vogel commented Aug 24, 2018

Sorry I overlooked that you @astafan8 were so thorough with your tests ;-).
It is very simple what this PR does: If you have some axis tick at 1e-5 (unitless) it will be rendered as 0.00001 by default. In this PR the same formater gets registered so that it will be rendered as '1e-5'.

But you are right maybe this should live somewhere else, so that we get nice axis exponentials. Let me play around a little and see where to put it. (And it does not need to be a manual formater necessarily).

untitled
Ignore the label 'Voltage' ;-)

@Dominik-Vogel Dominik-Vogel changed the title add axis tick format for unitless axis Format ticks for non-SI-unit axis in a more readable way Aug 24, 2018
@Dominik-Vogel
Copy link
Contributor Author

I added standard formatting now where the plots get generated.
This all is just a minor detail.
The plot looks good now:
capture

@ThorvaldLarsen
Copy link
Contributor

@Dominik-Vogel looks great! Concerning the placement of 1e-5 I think it would make sense to place inside the unit brackets as it really is part of the unit after rescaling: Flux (1e-5 e^2/hbar).

@Dominik-Vogel
Copy link
Contributor Author

@ThorvaldLarsen I totally agree. But my impresion is that we should prioritize it lower as the plotting front end will change soon and it requires some extra tweaking. If it is very important to you, then we can certainly change it.

@ThorvaldLarsen
Copy link
Contributor

Not really important. Was only if it was a quick change.

Copy link
Contributor

@astafan8 astafan8 left a comment

Choose a reason for hiding this comment

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

now i get it. very good default now! :)

@astafan8
Copy link
Contributor

@Dominik-Vogel there is some problem in CI when the notebook gets executed for docs.

@Dominik-Vogel
Copy link
Contributor Author

@astafan8 yes I noticed... It is quite cumbersome.... it comes from an example where two graphs are plotted into the same axes.... Maybe it is after all easier to do it as Thorvald suggested....

@Dominik-Vogel
Copy link
Contributor Author

Hopefully the final version... I now use the same logic as is used for the SI units but instead of prepending the unit character (k, M, T...) I prepend the exponent (always going to the closest multiple of 3):

figure_1

(Yes If this works I will update the docstring, just to say before you do it @astafan8 ;-))

@astafan8
Copy link
Contributor

please add tests if you have time ;)

Copy link
Contributor

@astafan8 astafan8 left a comment

Choose a reason for hiding this comment

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

Nice!

`_UNITS_FOR_RESCALING`.
The units for which unit prefixes ared added can be found in
`_UNITS_FOR_RESCALING`. For all other units an exponential sacling factor
is added to the label i.e. `(10^3 x e^2/hbar)`.
Copy link
Contributor

Choose a reason for hiding this comment

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

typos in this text :)

return f'{label} ({unit})'
label = f'{label}'
if unit != '' and unit is not None:
label += f' ({unit})'
Copy link
Contributor

Choose a reason for hiding this comment

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

sweet!

if postfix != '':
assert f"{base_label} ({postfix})" == label
else:
assert f"{base_label}" == label
Copy link
Contributor

Choose a reason for hiding this comment

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

the test method became too complex: it basically mirrors the logic of the function under test. Such a test becomes difficult to read and more difficult to modify. Let's be careful next time. As the initial author of the test, i should've also been more careful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Thanks for pointing that out, I got carried away ;-)

@jenshnielsen
Copy link
Collaborator

Hypothesis prints a warning that we probably need to fix

qcodes/tests/dataset/test_plotting.py::test_rescaled_ticks_and_units
  /home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/hypothesis/strategies.py:587: 
HypothesisDeprecationWarning: Cannot sample from {'', 'permille', 'm', 'g', 'T', 'ohm', 'Pa', '%', 'W', 'F', 'Ω', 
'K', 'eV', 'unit', 'kg', 's', 'Wb', 'nW', 'S', 'N', 'rad', 'H', 'mol', 'V', 'A', 'Ohm', 'Hz', 'C', 'J'}, not an ordered 
collection. Hypothesis goes to some length to ensure that the sampled_from strategy has stable results 
between runs. To replay a saved example, the sampled values must have the same iteration order on 
every run - ruling out sets, dicts, etc due to hash randomisation. Most cases can simply use 
`sorted(values)`, but mixed types or special values such as math.nan require careful handling - and note 
that when simplifying an example, Hypothesis treats earlier values as simpler.

@jenshnielsen
Copy link
Collaborator

@Dominik-Vogel Do you want to simplify the tests or should we just merge as is?

@codecov
Copy link

codecov bot commented Sep 5, 2018

Codecov Report

Merging #1243 into master will increase coverage by 0.03%.
The diff coverage is 93.75%.

@@            Coverage Diff             @@
##           master    #1243      +/-   ##
==========================================
+ Coverage   70.64%   70.67%   +0.03%     
==========================================
  Files          74       74              
  Lines        8160     8165       +5     
==========================================
+ Hits         5765     5771       +6     
+ Misses       2395     2394       -1

@Dominik-Vogel
Copy link
Contributor Author

@jenshnielsen I would love to merge it already.... I think the tests are not great but ok...

@jenshnielsen jenshnielsen merged commit 631d956 into microsoft:master Sep 5, 2018
giulioungaretti pushed a commit that referenced this pull request Sep 5, 2018
Merge: 160093f 3b7c698
Author: Jens Hedegaard Nielsen <jenshnielsen@gmail.com>

    Merge pull request #1243 from Dominik-Vogel/fix/plotting/ticks_unitless
giulioungaretti pushed a commit that referenced this pull request Sep 6, 2018
Merge: 160093f 3b7c698
Author: Jens Hedegaard Nielsen <jenshnielsen@gmail.com>

    Merge pull request #1243 from Dominik-Vogel/fix/plotting/ticks_unitless
@Dominik-Vogel Dominik-Vogel deleted the fix/plotting/ticks_unitless branch November 27, 2018 15:34
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.

None yet

5 participants