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

Colorbar tick formatting #25

Merged
merged 9 commits into from
May 30, 2019

Conversation

wwymak
Copy link
Contributor

@wwymak wwymak commented May 26, 2019

wwymak [9:52 PM]

  • implementation for adding a tick formatting option to the colorbars in geoplot and scatterplot as an alternative to the default scientific notation.
  • options for this field are:
    • None (the default scientific notation)
    • string in one of the bokeh formats which gets converted to a NumeralTickFormatter
    • an instance of one of the subclasses of bokeh.models.TickFormatter, which gets passed as is to the colorbar options.

@PatrikHlobil this works for the geoplot but I am not sure what your testing procedure is (and also what you would like me to do for the documentation?)

@PatrikHlobil
Copy link
Owner

PatrikHlobil commented May 26, 2019

@wwymak:

Cool, thanks a lot for your effort. I have a comment on your code: I think we can simplify this even more. Consider importing only:

from bokeh.models import TickFormatter

then you can make the check like:
def get_tick_formatter(formatter_arg):

def get_tick_formatter(formatter_arg):

    if issubclass(type(formatter_arg), TickFormatter) :
        return formatter_arg
    elif isinstance(formatter_arg, str):
        return NumeralTickFormatter(format=formatter_arg)
    else:
       raise ValueError("<colorbar_tick_format> parameter only accepts a string or a objects of bokeh.models.formatters.")

Then this is a really small & nice integration of the feature. About tests, I haven't so far integrated all my tests for geoplots so far in the project.

Could you write a 1 or 2 nice examples for the documentation (README.md), maybe one with the string and one with a formatter? Then, we could use these examples as test code for this feature!

Cheers, Patrik

@wwymak
Copy link
Contributor Author

wwymak commented May 27, 2019

ah, yeap, you are right-- isinstance returns True also for the parent class (I thought you need to be more specific than just checking for TickFormatter).

Have also updated the documentation with the 2 examples of customising the colorbar tick labels.

@wwymak wwymak marked this pull request as ready for review May 27, 2019 17:57
README.md Outdated

If you want to display the numerical labels on your colorbar with an alternative to the scientific format, you
can pass in a one of the [bokeh number string formats](https://bokeh.pydata.org/en/latest/_modules/bokeh/models/formatters.html#NumeralTickFormatter)
or an instance of one of the [bokeh.modles.fomrmatters](bokeh.models.formatters) to the `colorbar_tick_format` argument
Copy link
Owner

Choose a reason for hiding this comment

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

Bokeh.models.formatters

Copy link
Owner

@PatrikHlobil PatrikHlobil left a comment

Choose a reason for hiding this comment

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

Nicely done. Thanks for the extensive documentation also. If you correct my minor comments, also don’t forget to add your name to the CONTRIBUTORS.md file 👌🏼.

Cheers Patrik

category="Delta_Population_2017",
simplify_shapes=5000,
colormap="Inferno",
colorbar_tick_format=PrintfTickFormatter(format="%4.2f"))
Copy link
Owner

Choose a reason for hiding this comment

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

Nice example 😉

@@ -143,6 +147,17 @@ def convert_geoDataFrame_to_patches(gdf, geometry_column_name="geometry"):
return gdf_new


def get_tick_formatter(formatter_arg):

if isinstance(formatter_arg, TickFormatter):
Copy link
Owner

Choose a reason for hiding this comment

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

Shouldn’t this be issubclass here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, because issubclass requires the argument to be a class, so if you pass in e.g. issubclass("0.0a", TickFormatter) it will throw a TypeError issubclass() arg 1 must be a class. However, isinstance(formatter_arg, TickFormatter) works
Screenshot 2019-05-27 at 20 48 05

Copy link
Owner

Choose a reason for hiding this comment

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

Yes, but you can use:

issubclass(a.__class__, TickFormatter)

Just a matter of taste. I just think that with issubclass it is a bit clearer what happens here. Do whatever you like 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 sure. Have changed it to issubclass.

@PatrikHlobil
Copy link
Owner

Cool, this looks perfect for me. We should also add some tests, but we could do this in another pr if you want.

Did you run the tests already? Otherwise I have to check it out and would then like to merge the branch 😉

@wwymak
Copy link
Contributor Author

wwymak commented May 30, 2019

Did you run the tests already?

Hmm, only test_GeoPandasBokeh.py -- do you want me to run the other ones as well?

We should also add some tests, but we could do this in another pr if you want

Yeah, that might be easier 😉

@PatrikHlobil PatrikHlobil merged commit e0e8427 into PatrikHlobil:master May 30, 2019
@PatrikHlobil
Copy link
Owner

@wwymak : thanks again for helping me improve Pandas Bokeh. Do you plan to implement the tests yourself? The tests are very rudimentary at the moment and basically only check if the provided examples of the documentation run (better than nothing 😔).

@wwymak
Copy link
Contributor Author

wwymak commented May 31, 2019

@PatrikHlobil I am happy to add tests, but I am not quite sure what's your testing policy? (as far as I can tell for geoplots you are mostly testing it doesn't throw an error when it plots ?) Or do you add visual tests as well?

@PatrikHlobil
Copy link
Owner

@wwymak: you are right, I basically check if the Generation an html Export of the plots break on changes. Therefore, I use at the moment just the examples of the README.md. For Geoplots, I just implemented 2 tests so far and I haven’t found time to implement the rest. There are no direct visual tests so far, but the tests create html files with the test plots under the Tests/plot folder. However, I do only check them before releasing a new version on PyPI.

When I would start now with the problem, I would write it in a better testable way, but in the moment I am glad if the examples run and one can see obvious breaking changes.

If you want and have the time, you could also implement the remaining Geoplots of the documentation in the tests 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants