File size: 3,687 Bytes
164d1c0
 
 
 
 
 
 
731c0dd
164d1c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
731c0dd
 
 
164d1c0
731c0dd
 
 
 
 
 
164d1c0
 
731c0dd
164d1c0
 
1189f83
164d1c0
 
1189f83
164d1c0
 
1189f83
731c0dd
164d1c0
 
1189f83
731c0dd
164d1c0
 
e301a24
 
164d1c0
e301a24
 
164d1c0
 
 
e301a24
164d1c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0b30b31
164d1c0
 
 
b36c6ed
d3b1063
e301a24
164d1c0
 
b36c6ed
164d1c0
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import matplotlib.pyplot as plt
import matplotlib.colors as colors
import matplotlib.cm as cm
import matplotlib.gridspec as gridspec


def show_two_plots(gdf, name1, name2, vmin, vmax, colorscheme, title1, title2, label, split=False):
    print('split', split)
    if gdf.empty:
        raise ValueError("GeoDataFrame is empty")

    required_cols = [name1, name2]
    for col in required_cols:
        if col not in gdf.columns:
            raise ValueError(f"Column '{col}' not found in gdf")

    #Create a shared colormap and normalization
    cmap = plt.colormaps[colorscheme]
    norm = colors.Normalize(vmin=vmin, vmax=vmax)
    
    # Create subplots
    fig = plt.figure(figsize=(12, 6))
    gs = gridspec.GridSpec(1, 3, width_ratios=[1, 1, 0.05], wspace=0.3)

    axes = [fig.add_subplot(gs[0]), fig.add_subplot(gs[1]), fig.add_subplot(gs[2]) ]

    if split == False:
        # First plot 
        gdf.plot(column=name1, cmap=cmap, norm=norm, ax=axes[0], marker='s', markersize=10)
    
    else:
        # Split data into three GeoDataFrames
        # below_100 = gdf[gdf[split] <= 100]
        above_capacity = gdf[gdf[split] > (100-gdf['%Construccion'])]
        above_100 = gdf[gdf[split] > 100]
        above_colors = {"capacity":"chocolate", "100":"firebrick"}
        
        # Plot values ≤ 100 using colormap
        gdf.plot(column=name1, cmap=colorscheme, ax=axes[0], vmin=vmin, vmax=vmax, marker='s', markersize=10)
        
        # Plot values > capacity in orange
        above_capacity.plot(color=above_colors['capacity'], ax=axes[0], label='> capacidad debido a la construcción', marker='x', markersize=6)
        
        # Plot values > 100 in red
        above_100.plot(color=above_colors['100'], ax=axes[0], label='> 100% cobertura arbórea', marker='x', markersize=6)
        
        # Add legend manually for orange points
        orange_patch = plt.Line2D([0], [0], marker='o', color='w', label='> capacidad debido a la construcción', 
                               markerfacecolor=above_colors['capacity'], markersize=8)
    
        # Add legend manually for red points
        red_patch = plt.Line2D([0], [0], marker='o', color='w', label='> 100% cobertura arbórea', 
                               markerfacecolor=above_colors['100'], markersize=8)
        
        axes[0].legend(handles=[orange_patch, red_patch])
    # axes[0].set_title(title1)
    axes[0].set_title(title1, pad=-30)
    axes[0].set_axis_off()
    


    # Second plot (original)
    gdf.plot(column=name2, cmap=cmap, norm=norm, ax=axes[1],marker='s', markersize=10)
    axes[1].set_title(title2, pad=-30)
    axes[1].set_axis_off()
    

    # Shared colorbar
    sm = cm.ScalarMappable(cmap=cmap, norm=norm)
    sm._A = []  # Dummy array for the colormap
    cbar = fig.colorbar(sm, cax=axes[2], orientation='vertical', fraction=0.03, pad=0.02)
    cbar.set_label(label)
    
    return fig

def show_one_plot(gdf, name, vmin, vmax, colorscheme, title, label):
    # Second set of plots
    cmap = plt.colormaps[colorscheme]
    norm = colors.Normalize(vmin, vmax)

    # Create subplots
    fig = plt.figure(figsize=(12, 6))
    gs = gridspec.GridSpec(1, 2, width_ratios=[1, 0.025], wspace=0.3)

    axes = [fig.add_subplot(gs[0]), fig.add_subplot(gs[1])]
    

    gdf.plot(column=name, cmap=cmap, norm=norm, ax=axes[0], marker='s', markersize=10)
    axes[0].set_title(title, pad=-30)
    axes[0].set_axis_off()

    # Add a colorbar
    sm = cm.ScalarMappable(cmap=cmap, norm=norm)
    sm._A = []  # Dummy data for the colorbar
    cbar = fig.colorbar(sm, cax=axes[1], orientation='vertical', fraction=0.03, pad=0.02)
    cbar.set_label(label)


    return fig