-
Notifications
You must be signed in to change notification settings - Fork 5
feat: support subplots in py-maidr using maidr-ts #147
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
748d99d
feat: support multilayer plot using maidr-ts
dakshpokar 9f0d6ac
fix: support js engine without panel and layer based maidr data
dakshpokar 36f51fc
fix: rename 'panels' to 'subplots' for consistency with maidr-ts
dakshpokar 9770c1e
fix: address co-pilot comments and add jupyter notebook example for m…
dakshpokar d3d734e
fix: update MAIDR_TS_CDN_URL to use the production CDN instead of the…
dakshpokar e003c21
feat: support multipanel plots in pymaidr using maidr-ts
dakshpokar 8cf6a56
fix: correct title typo in bar plot example and update MAIDR_TS_CDN_U…
dakshpokar 47801cb
fix: co-pilot suggestions
dakshpokar e745cf5
Merge remote-tracking branch 'origin/main' into feat/multipanel
dakshpokar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
import maidr | ||
|
||
""" | ||
Create a simple multilayer plot with a bar chart and a line chart. | ||
|
||
Returns | ||
------- | ||
Tuple[plt.Figure, plt.Axes] | ||
The figure and axes objects of the created plot. | ||
|
||
Examples | ||
-------- | ||
>>> fig, ax = create_multilayer_plot() | ||
>>> isinstance(fig, plt.Figure) | ||
True | ||
""" | ||
maidr.set_engine("ts") | ||
# Generate sample data | ||
x = np.arange(5) | ||
bar_data = np.array([3, 5, 2, 7, 3]) | ||
line_data = np.array([10, 8, 12, 14, 9]) | ||
|
||
# Create a figure and a set of subplots | ||
fig, ax1 = plt.subplots(figsize=(8, 5)) | ||
|
||
# Create the bar chart on the first y-axis | ||
ax1.bar(x, bar_data, color="skyblue", label="Bar Data") | ||
ax1.set_xlabel("X values") | ||
ax1.set_ylabel("Bar values", color="blue") | ||
ax1.tick_params(axis="y", labelcolor="blue") | ||
|
||
# Create a second y-axis sharing the same x-axis | ||
ax2 = ax1.twinx() | ||
|
||
# Create the line chart on the second y-axis | ||
ax2.plot(x, line_data, color="red", marker="o", linestyle="-", label="Line Data") | ||
ax2.set_xlabel("X values") | ||
ax2.set_ylabel("Line values", color="red") | ||
ax2.tick_params(axis="y", labelcolor="red") | ||
|
||
# Add title and legend | ||
plt.title("Multilayer Plot Example") | ||
|
||
# Add legends for both axes | ||
lines1, labels1 = ax1.get_legend_handles_labels() | ||
lines2, labels2 = ax2.get_legend_handles_labels() | ||
ax1.legend(lines1 + lines2, labels1 + labels2, loc="upper left") | ||
|
||
# Adjust layout | ||
fig.tight_layout() | ||
|
||
# plt.show() | ||
maidr.show(fig) | ||
# maidr.save_html(fig, "multi-layer.html") |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Example of creating a multipanel plot with matplotlib. | ||
|
||
This script demonstrates how to create a figure with multiple panels | ||
containing different types of plots: line plot, bar plot, and scatter plot. | ||
""" | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
import maidr | ||
|
||
maidr.set_engine("ts") | ||
|
||
x_line = np.array([1, 2, 3, 4, 5, 6, 7, 8]) | ||
y_line = np.array([2, 4, 1, 5, 3, 7, 6, 8]) | ||
|
||
# Data for bar plot | ||
categories = ["A", "B", "C", "D", "E"] | ||
values = np.random.rand(5) * 10 | ||
|
||
# Data for bar plot | ||
categories_2 = ["A", "B", "C", "D", "E"] | ||
values_2 = np.random.randn(5) * 100 | ||
|
||
# Data for scatter plot | ||
x_scatter = np.random.randn(50) | ||
y_scatter = np.random.randn(50) | ||
|
||
# Create a figure with 3 subplots arranged vertically | ||
fig, axs = plt.subplots(3, 1, figsize=(10, 12)) | ||
|
||
# First panel: Line plot | ||
axs[0].plot(x_line, y_line, color="blue", linewidth=2) | ||
axs[0].set_title("Line Plot: Random Data") | ||
axs[0].set_xlabel("X-axis") | ||
axs[0].set_ylabel("Values") | ||
axs[0].grid(True, linestyle="--", alpha=0.7) | ||
|
||
# Second panel: Bar plot | ||
axs[1].bar(categories, values, color="green", alpha=0.7) | ||
axs[1].set_title("Bar Plot: Random Values") | ||
axs[1].set_xlabel("Categories") | ||
axs[1].set_ylabel("Values") | ||
|
||
# Third panel: Bar plot | ||
axs[2].bar(categories_2, values_2, color="blue", alpha=0.7) | ||
axs[2].set_title("Bar Plot 2: Random Values") | ||
axs[2].set_xlabel("Categories") | ||
axs[2].set_ylabel("Values") | ||
|
||
# Adjust layout to prevent overlap | ||
plt.tight_layout() | ||
|
||
# Display the figure | ||
maidr.show(fig) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Example of creating a multipanel plot with seaborn. | ||
|
||
This script demonstrates how to create a figure with multiple panels | ||
containing different types of plots using seaborn: line plot, bar plot, and bar plot. | ||
""" | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
import seaborn as sns | ||
|
||
import maidr | ||
|
||
# Set the plotting style | ||
sns.set_theme(style="whitegrid") | ||
|
||
# Set the maidr engine | ||
maidr.set_engine("ts") | ||
|
||
# Data for line plot | ||
x_line = np.array([1, 2, 3, 4, 5, 6, 7, 8]) | ||
y_line = np.array([2, 4, 1, 5, 3, 7, 6, 8]) | ||
line_data = {"x": x_line, "y": y_line} | ||
|
||
# Data for first bar plot | ||
categories = ["A", "B", "C", "D", "E"] | ||
values = np.random.rand(5) * 10 | ||
bar_data = {"categories": categories, "values": values} | ||
|
||
# Data for second bar plot | ||
categories_2 = ["A", "B", "C", "D", "E"] | ||
values_2 = np.random.randn(5) * 100 | ||
bar_data_2 = {"categories": categories_2, "values": values_2} | ||
|
||
# Create a figure with 3 subplots arranged vertically | ||
fig, axs = plt.subplots(3, 1, figsize=(10, 12)) | ||
|
||
# First panel: Line plot using seaborn | ||
sns.lineplot(x="x", y="y", data=line_data, color="blue", linewidth=2, ax=axs[0]) | ||
axs[0].set_title("Line Plot: Random Data") | ||
axs[0].set_xlabel("X-axis") | ||
axs[0].set_ylabel("Values") | ||
|
||
# Second panel: Bar plot using seaborn | ||
sns.barplot( | ||
x="categories", y="values", data=bar_data, color="green", alpha=0.7, ax=axs[1] | ||
) | ||
axs[1].set_title("Bar Plot: Random Values") | ||
axs[1].set_xlabel("Categories") | ||
axs[1].set_ylabel("Values") | ||
|
||
# Third panel: Bar plot using seaborn | ||
sns.barplot( | ||
x="categories", y="values", data=bar_data_2, color="blue", alpha=0.7, ax=axs[2] | ||
) | ||
axs[2].set_title("Bar Plot 2: Random Values") # Fixed the typo in the title | ||
axs[2].set_xlabel("Categories") | ||
axs[2].set_ylabel("Values") | ||
|
||
# Adjust layout to prevent overlap | ||
plt.tight_layout() | ||
|
||
# Display the figure | ||
maidr.show(fig) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.