truelearn.utils.visualisations.WordPlotter#

class truelearn.utils.visualisations.WordPlotter[source]#

Bases: MatplotlibBasePlotter

Word cloud plotter.

In word cloud plotter, each knowledge is represented by some words of a certain size and colour.

The size of the words is proportional to the mean of the knowledge component the word represents.

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

Methods

__init__()

Init a word cloud plotter.

plot(content[, topics, top_n])

Plot the graph based on the given data.

savefig(file, **kargs)

Export the visualisation to a file.

show()

Display the figure if the caller is in an interactive environment.

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__()[source]#

Init a word cloud plotter.

plot(content: Knowledge, topics: Optional[Iterable[str]] = None, top_n: Optional[int] = None, **kwargs) 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.

  • **kwargs

    Additional arguments that control the instantiation of the WordCloud object.

    You can pass in all the parameters supported by WordCloud object. You can refer to wordcloud documentation for all the supported arguments.

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”.

    You can use print(plotter.fig.canvas.get_supported_filetypes()) to find out the supported file formats in your platform.

    You can optionally pass in these arguments:
    dpi:

    The dpi of the image.

Notes

You can refer to matplotlib’s documentation for savefig to find out more supported arguments.

show()[source]#

Display the figure if the caller is in an interactive environment.

For example, if you use Jupyter Notebooks, it will be displayed.

If you want to display the visualisations in a non-interactive environment, you can use plt.show() instead.

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.