Skip to content

Direct on-terminal plot as option for headless situations #173

@sadielbartholomew

Description

@sadielbartholomew

On writing up #172 I had the thought that, to provide an immediate plot view in headless situations, or otherwise as a possibly useful 'quick look' feature, there are libraries that enable in-terminal primitive plots. It is firm 'bells and whistles' territory, but it is not too much code to add as a dependency to the 'climate-aware-task-scheduler[plots]' libraries some lightweight library like plotext which I've used for a brief demo below, to allow such a view.

Example

I had a quick play around and got this which I appended to the plotplan in the plotting module, to compare to the main matplotlib plot:

    import plotext as textplt
    textplt.date_form('d/m/Y H:M:S')

    def convert_dt_to_mins(dt):
        return textplt.datetimes_to_string(dt)

    conv_ci_times = convert_dt_to_mins(times)
    textplt.plot(conv_ci_times, values, fillx=True)
    textplt.plot(convert_dt_to_mins(now_times), now_values, fillx=True)
    textplt.plot(convert_dt_to_mins(opt_times), opt_values, fillx=True)

    textplt.xlim(min(conv_ci_times), max(conv_ci_times))
    textplt.ylim(0.0, max(values))

    textplt.show()

which produces:

Image

where the reference full matplotlib plot (going from my PR branch #171 which will update the plotting) that also emerges is:

Image

It's not perfect but for a quick-look it's decent enough...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions