chartify icon indicating copy to clipboard operation
chartify copied to clipboard

Support with statements to build clean plots

Open elben10 opened this issue 6 years ago • 3 comments

THIS IS FEATURE REQUEST

Environment:

  • Chartify version(s): '2.3.5'
  • Operating System(s): 'win32'
  • Python version(s): 3.7 (Conda)

I suggest to support the with statement in the following way:

import chartify
import pandas

class Chart(chartify.Chart):
    def __enter__(self):
        return self
    def __exit__(self, type, value, traceback):
        self.show()

df = pandas.DataFrame({'x': [1, 2, 3], 'y': [1, 2, 3]})

with Chart() as ch:
    ch.plot.line(df, 'x', 'y')
    ch.set_title("Example")

This would allow a very simple and clean way of structuring one's plots.

elben10 avatar Dec 14 '18 07:12 elben10

Or maybe this to run plots out of the box in google colab.

class Chart(chartify.Chart):
    def __enter__(self):
        import bokeh
        bokeh.io.output_notebook()
        return self
    def __exit__(self, type, value, traceback):
        self.show()

elben10 avatar Dec 14 '18 07:12 elben10

@elben10 did you manage to get an HTML-rendered output for Colab? I can only get PNG output, and even that requires installing chromedriver on the colab's virtual machine.

vadymhimself avatar Jun 18 '19 19:06 vadymhimself

Try to take a look at this notebook. https://colab.research.google.com/notebooks/charts.ipynb#scrollTo=nv8P3UYm6SiQ

You need to use output_notebook function within the cell.

elben10 avatar Jun 18 '19 20:06 elben10