Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #558 add matplotlib example #2179

Merged
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
e836adb
add matplotlib chart example
AbisoyeOnanuga Oct 28, 2024
7c7c237
add matplotlib taipy chart example
AbisoyeOnanuga Oct 28, 2024
40ac40e
add matplotlib scatter md py
AbisoyeOnanuga Oct 28, 2024
f5c15ab
update matplotlib scatter md
AbisoyeOnanuga Oct 28, 2024
8036a1e
update matplotlib scatter py
AbisoyeOnanuga Oct 28, 2024
62de9a1
update matplotlib scatter
AbisoyeOnanuga Oct 28, 2024
6b92322
update matplotlib scatter
AbisoyeOnanuga Oct 28, 2024
117e200
move to matplotlib folder
AbisoyeOnanuga Oct 28, 2024
4d68408
add custom css
AbisoyeOnanuga Oct 28, 2024
911a802
moved matplotlib example files
AbisoyeOnanuga Oct 28, 2024
8eaa8a2
Add an example on how to integrate Matplotlib
AbisoyeOnanuga Oct 28, 2024
ff9c948
update matplotlib scatter chart example
AbisoyeOnanuga Oct 28, 2024
366fb20
update matplotlib scatter example
AbisoyeOnanuga Oct 28, 2024
3bac8d7
update matplotlib scatter example
AbisoyeOnanuga Oct 28, 2024
ba304a8
Merge branch 'develop' into issue-558-add-matplotlib-example
AbisoyeOnanuga Oct 28, 2024
002411d
Merge branch 'develop' into issue-558-add-matplotlib-example
AbisoyeOnanuga Oct 30, 2024
42f157d
udpate matplotlib example
AbisoyeOnanuga Oct 30, 2024
6498933
update matplotlib example
AbisoyeOnanuga Oct 30, 2024
091b312
update matplotlib example
AbisoyeOnanuga Oct 30, 2024
ed305c3
udate matplotlib_scatter
AbisoyeOnanuga Oct 30, 2024
2658f96
update matplotlib example for taipy 4.0.0
AbisoyeOnanuga Oct 31, 2024
be97527
update matplotlib example
AbisoyeOnanuga Oct 31, 2024
5777d5c
update matplotlib example
AbisoyeOnanuga Oct 31, 2024
3710be0
Merge branch 'Avaiga:develop' into issue-558-add-matplotlib-example
AbisoyeOnanuga Oct 31, 2024
9f46838
update matplotlib example
AbisoyeOnanuga Oct 31, 2024
b4cccf2
update matplotlib example
AbisoyeOnanuga Oct 31, 2024
062d3a9
update matplotlib example
AbisoyeOnanuga Oct 31, 2024
dfc264c
remove import os
AbisoyeOnanuga Oct 31, 2024
88d1d8b
Merge branch 'develop' into issue-558-add-matplotlib-example
FredLL-Avaiga Oct 31, 2024
97b2852
update matplotlib image example
AbisoyeOnanuga Oct 31, 2024
1de58e7
update matplotlib_image, rename markdown_example
AbisoyeOnanuga Oct 31, 2024
8d38f3f
update matplotlib_image
AbisoyeOnanuga Oct 31, 2024
986d137
update matplotlib_image: sort imports
AbisoyeOnanuga Oct 31, 2024
800ab90
Merge branch 'Avaiga:develop' into issue-558-add-matplotlib-example
AbisoyeOnanuga Nov 1, 2024
5733179
Merge branch 'develop' into issue-558-add-matplotlib-example
AbisoyeOnanuga Nov 2, 2024
d4360f2
Fix import order in matplotlib_image.py
AbisoyeOnanuga Nov 2, 2024
ed1a4e3
Merge branch 'develop' into issue-558-add-matplotlib-example
AbisoyeOnanuga Nov 3, 2024
7001296
Merge branch 'develop' into issue-558-add-matplotlib-example
AbisoyeOnanuga Nov 5, 2024
9dc1834
Merge branch 'develop' into issue-558-add-matplotlib-example
FredLL-Avaiga Nov 13, 2024
98495f4
Merge branch 'develop' into issue-558-add-matplotlib-example
AbisoyeOnanuga Nov 13, 2024
3bfa5bd
rename to image.py
AbisoyeOnanuga Nov 13, 2024
88caa19
Merge branches 'issue-558-add-matplotlib-example' and 'issue-558-add-…
AbisoyeOnanuga Nov 13, 2024
13fd293
fix linter sort imports
AbisoyeOnanuga Nov 13, 2024
33c18cb
rename back to markdown.py
AbisoyeOnanuga Nov 13, 2024
c23a135
remove one line
AbisoyeOnanuga Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions doc/gui/examples/charts/matplotlib/matplotlib_scatter.py
FredLL-Avaiga marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Copyright 2021-2024 Avaiga Private Limited
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
# -----------------------------------------------------------------------------------------
# To execute this script, make sure that the taipy-gui package is installed in your
# Python environment and run:
# python <script>
# -----------------------------------------------------------------------------------------
# Matplotlib scatter chart example
from taipy.gui import Gui
import matplotlib.pyplot as plt
import numpy as np
import mpld3

# Define data
employee_performance = [2, 3.5, 2, 3.5, 3, 4]
happiness_scores = [2, 3, 4, 3, 2, 3]

# Calculate sizes based on product of performance and happiness, scaled to 1-100%
sizes = [e * h * 20 for e, h in zip(employee_performance, happiness_scores)]
colors = sizes # Color based on sizes

# Create the Matplotlib figure
fig, ax = plt.subplots(figsize=(10, 5.2)) # Adjust figsize for a slightly smaller chart
scatter = ax.scatter(employee_performance, happiness_scores, s=sizes, c=colors, cmap="Greens", vmin=min(colors), vmax=max(colors))
ax.set(xlim=(1, 6), xticks=np.arange(1, 7), ylim=(1, 6), yticks=np.arange(1, 7))
ax.set_xlabel('Performance Score')
ax.set_ylabel('Happiness Index')
ax.set_title('Employee Performance vs. Happiness')

# Example labels for bubbles
for i in range(len(employee_performance)):
ax.text(employee_performance[i], happiness_scores[i], f'Emp {i+1}', fontsize=12, ha='right')

# Scale sizes to percentages
scaled_sizes = [size / max(sizes) * 100 for size in sizes]

# Create legend with employee labels and matching bubble colors and percentages
scaled_sizes = [size / max(sizes) * 100 for size in sizes]
handles = [
plt.Line2D(
[0], [0], marker='o', color='w',
markerfacecolor=plt.cm.Greens(color / max(colors)),
markersize=np.sqrt(size) / 1,
label=f'Emp {i+1} ({int(size)}%)'
)
for i, (color, size) in enumerate(zip(colors, scaled_sizes))
]
legend1 = ax.legend(handles=handles, title="Employees and Efficiency (%)", loc="center left", bbox_to_anchor=(1, 0.5), frameon=True, fontsize=10, labelspacing=2)
ax.add_artist(legend1)

# Positioning the legend to avoid clipping
legend1 = ax.legend(handles=handles, title="Employees and Efficiency (%)", loc="center right", bbox_to_anchor=(-0.2, 0.5), frameon=True, fontsize=10, labelspacing=2)
ax.add_artist(legend1)

# Adjust layout to ensure everything fits
plt.tight_layout(rect=[0, 0, 0.75, 1]) # Adjust the rect parameter to leave space for the legend

# Define Taipy page content
page = """
<|toggle|theme|>

<center style="color: var(--taipy-primary); font-size: 2.5em; font-weight:bold">
FredLL-Avaiga marked this conversation as resolved.
Show resolved Hide resolved
**Matplotlib**{: .color-primary} 2D Scatter Plot
</center>
This page contains a 2D scatter plot created with Matplotlib:
<br/><br/>

<|part|content={fig}|>
FredLL-Avaiga marked this conversation as resolved.
Show resolved Hide resolved
"""

if __name__ == "__main__":
Gui(page, css_file="styles.css").run(title="Chart-Scatter-Matplotlib")
11 changes: 11 additions & 0 deletions doc/gui/examples/charts/matplotlib/styles.css
FredLL-Avaiga marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
img {
display: block;
margin: auto;
}

div.taipy-part.MuiBox-root {
FredLL-Avaiga marked this conversation as resolved.
Show resolved Hide resolved
height: 560px;
display: flex;
align-items: center;
justify-content: center;
}
Loading