Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ultimate-Storm committed Dec 13, 2023
1 parent 409b090 commit 64da054
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 52 deletions.
8 changes: 7 additions & 1 deletion wanshi/visualizations/crona/guide_line_heatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,11 @@ ht_map <- Heatmap(
column_names_rot = 45,
)

# Draw the heatmap with gaps between row groups
# Open the SVG Graphics Device
#svg("heatmap.svg", width = 8, height = 6) # Adjust 'width' and 'height' as needed

# Draw the heatmap
draw(ht_map)

# Close the SVG Graphics Device
#dev.off()
55 changes: 4 additions & 51 deletions wanshi/visualizations/crona/special_needs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import met_brewer
from decide_my_facourite_color import *
# Set the font globally
mpl.rcParams['font.family'] = 'Arial' # or 'Helvetica' if available

csv_path = 'META-AI_ Guideline Items - Tabellenblatt1.csv'
core_data = 'core data.csv'
import csv

# read csv with pandas
df = pd.read_csv(csv_path, sep=',', header=0, index_col=0)
Expand Down Expand Up @@ -40,21 +38,15 @@
df_core_data = pd.read_csv(core_data, sep=',', header=0, index_col=0, encoding='utf-8', engine='python')
first_column_core = df_core_data.iloc[:,0]
cata_count = df_core_data.groupby('cata')['test'].count()
#print(cata_count)


##########################
sector = circos.sectors[0]
#print(sector.name)
track1 = sector.add_track((100, 100))
track1.axis()
#print(int(track1.size))

pos_list = list(range(0, int(track1.size)))
# add 0.5 to all positions
pos_list = [x + 0.5 for x in pos_list]
#print(len(pos_list))
# Plot rect & text (style1)

for i in range(int(track1.size)):
start, end = i, i + 1
track1.rect(start, end, fc='white', ec="black", lw=1)
Expand Down Expand Up @@ -84,40 +76,29 @@
for i in range(int(track2.size)):
start, end = i, i + 1
track2.rect(start, end, ec="white", lw=1)
# track2.yticks('Groups of Items', tick_length=0, label_margin=2)
count = 0
first_column_core_enu = enumerate(first_column_core)
#print('----------')

items = list(guide_line_group.items())
#revert guide_line_group.items()
items.reverse()
count2 = 0

for key,value in items:

#print(count2)
#print(value)
end = count + value
# Access the color_guide_line_group list in reverse
inverse_index = len(color_guide_line_group) - count2 - 1
track2.rect(count, end, fc=color_guide_line_group[inverse_index])
#track2.text(str(key), (count + end) / 2, color="white", adjust_rotation=True, **{'size':8, 'va':"center"})
count2 += 1
count = end


##################
sector = circos.sectors[1]
#print(sector.name)
track1 = sector.add_track((90, 100))
track1.axis()
#print(int(track1.size))

pos_list = list(range(0, int(track1.size)))
# add 0.5 to all positions
pos_list = [x + 0.5 for x in pos_list]
#print(len(pos_list))
# Plot rect & text (style1)

track1.xticks(
Expand All @@ -142,8 +123,6 @@
track2 = sector.add_track((80, 90))
track2.axis()
guideline_list = ['G','G','G','G','G','S','S','G','S', 'G','G','S','G','S','S', 'G','S','G','G','G','S','S','S','S','S','G']
#print(len(guideline_list))
from collections import OrderedDict

for i in (range(0, int(track1.size))):
start, end = i, i + 1
Expand All @@ -152,11 +131,9 @@
else:
color = color_Guideline_Type[1]
track2.rect(start, end, fc=color, ec="black", lw=1)
#track2.text(str(guideline_list[i]), (end + start) / 2, size=8, color="white", adjust_rotation=False)
track3 = sector.add_track((70, 80))
year = [2009,2015,2016,2020,2020,2021,2022,2022,2023, 2019,2020,2020,2021,2022,2023, 2012,2020,2020,2020,2021,2021,2021,2021,2022,2022,2022]
unique_years = sorted(set(year))
#print(len(unique_years))
# Distribute color_year evenly across the unique years
color_mapping = [(yr, color_year[i % len(color_year)]) for i, yr in enumerate(unique_years)]

Expand All @@ -167,9 +144,6 @@
start, end = i, i + 1
track3.rect(start, end, fc=year_gradient_color_dict[year[i]], ec="black", lw=1)

#track3.text(str(year[i])[2:], (end + start) / 2, size=8, color="white",adjust_rotation=False)

#########

critirian_link_list = enumerate(all_critirian_names)
# transfer item_names from numpy array to list
Expand Down Expand Up @@ -211,27 +185,6 @@
labels2 = list(colors2.keys())
handles1 = [plt.Rectangle((0,0),1,1, color=colors1[label]) for label in labels1]
handles2 = [plt.Rectangle((0,0),1,1, color=colors2[label]) for label in labels2]
# plt.legend(handles, labels, loc=[1.,1.],title="Guideline Type", )
# add another legend to the figure
# import matplotlib.patches as mpatches
# blue_patch = mpatches.Patch(color='blue', label='blue legend')
# plt.legend(handles=[blue_patch])
ax1 = fig.add_axes([0.85, 0.88, 0.02, 0.1])
# fill the ax with gradient blue
# color_spam4 = mpl.cm.get_cmap('Blues', 16).gradient

norm = mpl.colors.Normalize(vmin=2008, vmax=2023)
# print(mpl.cm.ScalarMappable.get_clim(cmap = mpl.cm.Blues))
cmap = (mpl.colors.ListedColormap(color_year)
.with_extremes(over='0.25', under='0.75'))
cb1 = mpl.colorbar.ColorbarBase(ax1, cmap=cmap, norm=norm, orientation='vertical')
#cb1.set_label('Year', rotation=0, labelpad=10, loc='top', size=10)
# add color bar legend to the figure
# ax2 = fig.add_axes([0.85, 0.1, 0.02, 0.2], frameon=False, facecolor='g')
# cb1 = mpl.colorbar.ColorbarBase(ax2, cmap=mpl.cm.Greens, norm=norm, orientation='vertical')

fig.legends.append(plt.legend(handles1, labels1, loc=[-12.,0],title="Guideline Type"))
fig.legends.append(plt.legend(handles2, labels2, loc=[-20.,0],title="Level of Consensus"))
# fig.legends.append([ ['Cold', 'Medium', 'Hot'], ['Cold', 'Medium', 'Hot']])

fig.show()
fig.savefig('circle.svg', format='svg', dpi=1800)

fig.show()

0 comments on commit 64da054

Please sign in to comment.