Open Hamedloghmani opened 1 year ago
@Hamedloghmani @edwinpaul121 what would be the radius of bubbles? Running time, right?
@hosseinfani Exactly. Thanks for reminding me. @edwinpaul121 There will be another list of floats with the same size as 2 previous lists indicating the runtime. That would be the radius of the bubbles.
@hosseinfani @Hamedloghmani, Thank you for the clarification. I have created a function that I think should do what is required. Do let me know if any changes need to be made. The sizes (20,600) parameter will have to be changed based off of the min and max radius/runtime.
import matplotlib.pyplot as plt
import seaborn as sns
def bubble_plot_lstdata(lst_fair, lst_util, runtime):
'''
@args: list of float numbers (fairness)
list of float numbers (utilities)
list of float numbers (runtime)
'''
plt.rcParams['figure.figsize'] = [14, 8]
sns.set_style("darkgrid") # used just for a darker background with grids (not required)
# Plots data using seaborn
sns.scatterplot(x = lst_fair,
y = lst_util,
size = runtime,
sizes = (20,600),
alpha = 0.5
)
# Titles for x and y axes
plt.xlabel("Fairness Measure")
plt.ylabel("Utility Measure")
# Brings legend out of the graph region
plt.legend(bbox_to_anchor=(1, 1), loc='upper left', fontsize=10)
# Displays graph
plt.show()
Edit : Code format updated
Follow up to the previous comment, would it be better to upload the python file directly as the formatting doesn't seem to be working too well with this
@edwinpaul121 for better formatting, instead of "add code" feature you can use "Slash Commands" ( the square on the right with a slash inside of it). Then select "code block", "Python" and if you put your code inside that box, you'll be fine. you can edit your comment and try it out.
@edwinpaul121 @Hamedloghmani would you please run the code on a test case and also upload the generated figure. thanks.
First test values and figure :
x_vals = [1.2, 3.4, 5.6, 7.8, 9.0]
y_vals = [2.3, 4.5, 6.7, 8.9, 10.1]
sizes = [100, 200, 300, 400, 500]
Second test values and its figure:
xval = [0.695, 0.767, 1.058, 0.248, 0.381, 0.467, 0.2317]
yval = [0.126, 0.141, 0.247, 0.060, 0.083, 0.115, 0.0276]
size = [0.0569, 0.626, 0.811, 0.188, 0.298, 0.352, 0.2041]
Thank you @edwinpaul121 I'll double check the code and notify you for any potential changes soon. I have to push some changes in the repo before asking you to make a pull request.
Hi @edwinpaul121 I made some changes. 1- Changed some hard-coded values to arguments 2- Changed the style of doctsrings to Google format 3- Added a new argument as a flag to save the plot or not 4- Some minor changes Please take a look and see if it makes sense. If it does, you can make a pull request with the following code on main branch, Adila > src >util > visualization.py
import matplotlib.pyplot as plt
import seaborn as sns
def bubble_plot(fairness: list, utility: list, runtime: list, figsize: list = [14, 8], xlabel: str = "Fairness Metric", ylabel: str = "Utility Metric", save: bool = False):
"""
Args:
fairness: fairness metric values
utility: utility metric values
runtime: runtime of each sample
figsize: figure size for plot
xlabel: label for the x-axis on the plot
ylabel: label for the y-axis on the plot
save: flag to determine saving the plot
"""
plt.rcParams['figure.figsize'] = figsize
sns.set_style("darkgrid") # used just for a darker background with grids (not required)
# Plots data using seaborn
sns.scatterplot(x=fairness, y=utility, size=runtime, sizes=(min(runtime), max(runtime)), alpha=0.5)
# Titles for x and y axes
plt.xlabel(xlabel)
plt.ylabel(ylabel)
# Brings legend out of the graph region
plt.legend(bbox_to_anchor=(1, 1), loc='upper left', fontsize=10)
if save:
plt.savefig(f'{xlabel} vs {ylabel}.png')
# Displays graph
plt.show()
Hi @Hamedloghmani, the changes make sense, I'll make a pull request asap.
Hello @edwinpaul121
This is your first task and issue page in this project, welcome 😄
Your task is to design and implement a function to create a bubble plot from 2 given list of float numbers. One of these lists is fairness, the other one is utility. Consider the lists have the same length.
Please try to write the function as generic as possible as we discussed and include other necessary arguments to customize the plot. Some bubble plot samples can be found here
You can log your progress and problems here. Please let me know if you have any questions.
Thanks