Plots¶
Plots in Taipy Designer may be made with the following widget types:
- Python-based plots are available using Plolty Python or Matplotlib.
- Simplified usage (array properties) is available for Line chart, Bar chart or Pie chart. Otherwise, use the Plotly Python generic for a complete Plotly options and configurations.
- JavaScript-based plots are available Apache ECharts. They are usable by writing Python code with JSON-like dicts.
Plotly-based widgets share common parameters, especially hideModeBar which allows to hide plot options toolbar at dashboard play.
Line chart¶
Allows to quickly display line charts, when x and y axis are expressed as lists of numbers. The parameter numberOfAxis allows to specify up to 8 y-axis properties (named y1 to y8), sharing the same x-axis property (named x). Widget layout may be configured in the "Graphical properties" tab.
Bar chart¶
Here parameter numberOfAxis allows to specify couples of x and y axis properties (named x1, y1 to x8, y8).
Some examples:
Pie chart¶
This widget has two properties:
- values: an list of values to be displayed as pie chart.
- labels: an optional list of labels associated to values.
Example:
Plotly Python Generic¶
This widget expects a Plotly figure Python object. Here is a code example:
import plotly.express as px
df = px.data.gapminder().query("country=='Canada'")
fig = px.line(df, x="year", y="lifeExp", title='Life expectancy in Canada')
return fig
All recipes may be found in Ploty Python documentation.
No call to fig.show()
is needed because rendering process will be entirely handled by Taipy
Designer according to its rendering rules.
Example:
Matplotlib¶
In the same way as Plotly Python widget, Matplotlib widget expect a figure object as property. Below is a code example:
import matplotlib
matplotlib.use('Agg') # Use a non-interactive backend
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
fruits = ['apple', 'blueberry', 'cherry', 'orange']
counts = [40, 100, 30, 55]
bar_labels = ['red', 'blue', '_red', 'orange']
bar_colors = ['tab:red', 'tab:blue', 'tab:red', 'tab:orange']
ax.bar(fruits, counts, label=bar_labels, color=bar_colors)
ax.set_ylabel('fruit supply')
ax.set_title('Fruit supply by kind and color')
ax.legend(title='Fruit color')
All recipes may be found in Matplotlib documentation.
- No call to
plt.show()
is needed because rendering process will be entirely handled by Taipy Designer according to its rendering rules. -
It is important to select a non interactive backend for Matplotlib. This is achieved by the following directive:
import matplotlib matplotlib.use('Agg') # Use a non-interactive backend
Switching to the Agg backend for Matplotlib avoids using the Tkinter GUI entirely, as it is designed for saving images to files without rendering them on the screen.
Example:
ECharts¶
Simply, copy and paste the needed visualization from ECharts examples gallery and convert it to Python. This example shall return an option JSON according to ECharts grammar. Finally, bind this variable to the option widget property.
Some examples: