truelearn.utils.visualisations.TreePlotter#

class truelearn.utils.visualisations.TreePlotter(title: str = "Comparison of learner's subjects")[source]#

Bases: PlotlyBasePlotter

Treemap plotter.

In the treemap, each knowledge component is represented by a rectangle of a certain size and colour.

The size of the rectangle is proportional to the mean of the knowledge component.

The color of the rectangle is used to differentiate different knowledge components.

Methods

__init__([title])

Init a treemap plotter.

plot(content[, topics, top_n, history])

Plot the graph based on the given data.

savefig(file, **kargs)

Export the visualisation to a file.

show()

Display the visualisation in a new webpage.

title(text)

Set the title of the figure.

xlabel(text)

Set the x label of the figure.

ylabel(text)

Set the y label of the figure.

__init__(title: str = "Comparison of learner's subjects")[source]#

Init a treemap plotter.

Parameters:

title – The default title of the visualization

plot(content: Knowledge, topics: Optional[Iterable[str]] = None, top_n: Optional[int] = None, history: bool = False) Self[source]#

Plot the graph based on the given data.

It will not draw anything if the knowledge given by the user is empty, or if topics and top_n make the filtered knowledge empty.

Parameters:
  • content – The Knowledge object to use to plot the visualisation.

  • topics – The list of topics in the learner’s knowledge to visualise. If None, all topics are visualised (unless top_n is specified, see below).

  • top_n – The number of topics to visualise. E.g. if top_n is 5, then the top 5 topics ranked by mean will be visualised.

  • history – Whether to utilize history information in the visualisation. If this is set to True, an attribute called history must be present in all knowledge components.

savefig(file: str, **kargs)[source]#

Export the visualisation to a file.

Parameters:
  • file – The local file path in which to create the file.

  • **kargs

    Optional supported arguments as shown below.

    This method supports saving the visualisation in various formats. Most platforms support the following formats: “png”, “jpg” or “jpeg”, “svg”, “pdf”, “html”, “json”.

    If you want to export a HTML file, you can optionally pass in
    default_width:

    The default width of the image in the HTML file.

    default_height:

    The default height of the image in the HTML file.

    encoding:

    The encoding of the saved HTML file. If unspecified, the encoding will be utf-8.

    If you want to export a JSON file, you can optionally pass in
    pretty:

    Whether the saved JSON representation should be pretty-printed.

    encoding:

    The encoding of the saved JSON file. If unspecified, the encoding will be utf-8.

    If you want to export an image file, you can optionally pass in
    width:

    The default width of the image.

    height:

    The default height of the image.

Notes

You can refer to Plotly’s documentation for write_image and write_html to find out more supported arguments.

show()[source]#

Display the visualisation in a new webpage.

Equivalent to calling Plotly’s Figure.show() method.

title(text: str)[source]#

Set the title of the figure.

Parameters:

text – The title of the figure.

xlabel(text: str)[source]#

Set the x label of the figure.

Parameters:

text – The x label of the figure.

ylabel(text: str)[source]#

Set the y label of the figure.

Parameters:

text – The y label of the figure.