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 40 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
FredLL-Avaiga marked this conversation as resolved.
Show resolved Hide resolved
File renamed without changes.
85 changes: 85 additions & 0 deletions doc/gui/examples/charts/matplotlib/matplotlib_image.py
FredLL-Avaiga marked this conversation as resolved.
Show resolved Hide resolved
FredLL-Avaiga marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# 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>
# -----------------------------------------------------------------------------------------
import os

import matplotlib.pyplot as plt

from taipy.gui import Gui, Markdown


# Generate a scatter plot
x = [1, 2, 3, 4, 5] # x axis values
y = [10, 14, 12, 15, 18] # y axis values
sizes = [100, 100, 100, 100, 100] # Bubble sizes
colors = [30, 40, 50, 60, 70] # Bubble color values that will be mapped to shades of colormap (cmap)

# Scatter plot
# The `c` parameter uses the `colors` list to map values to the colormap (cmap)
# The `edgecolors` parameter sets the color of the edges around the bubbles
plt.scatter(x, y, s=sizes, c=colors, cmap='Greens', edgecolors='black', linewidths=1)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Matplotlib 2D Scatter Plot')

# Adding labels next to each point
for i in range(len(x)):
plt.text(x[i] + 0.1, y[i] - 0.1, f'Point {i+1}', fontsize=9, ha='left')

# Creating legend entries for each point
# Each entry corresponds to a point, with the color and label indicating the point's position.
# The `markerfacecolor` sets the fill color of the legend marker to match the point's color in the 'Greens' colormap.
# The `markeredgecolor` sets the edge color of the legend marker.
# The `markeredgewidth` sets the width of the edge.
handles = [
plt.Line2D(
[0], [0], marker='o', color='w',
markerfacecolor=plt.cm.Greens(color / max(colors)),
markersize=10, # Adjust the size for visibility
label=f'Point {i+1}',
markeredgewidth=1, # Thickness of the edge color
markeredgecolor='black' # Edge color to match the plot
) for i, color in enumerate(colors)
]

# Placing the legend on the left side of the chart
plt.legend(handles=handles, title="Points", loc="center left", bbox_to_anchor=(1, 0.5), frameon=True)

# Adjust the layout to ensure everything fits and nothing is clipped
plt.tight_layout(rect=[0, 0, 1, 1])

# Save the figure as a PNG image
output_dir = './images'
if not os.path.exists(output_dir):
os.makedirs(output_dir)
content = "./images/figure.png"
plt.savefig(content)

# Define Taipy page content
page_content = Markdown("""
# Matplotlib 2D Scatter Plot
<|{content}|image|class_name=scatter-plot|>
""", style={
".scatter-plot": {
"display": "block",
"margin": "auto",
"max-width": "100% !important",
"width": "max-content !important",
"height": "max-content !important"
}
})

if __name__ == "__main__":
Gui(page_content).run(title="Chart-Scatter-Matplotlib")
Loading