fffiloni commited on
Commit
ede48c3
·
verified ·
1 Parent(s): 2c0895b

debug warped map

Browse files
Files changed (1) hide show
  1. create_map_poster.py +23 -8
create_map_poster.py CHANGED
@@ -99,17 +99,18 @@ THEME = None # Will be loaded later
99
 
100
  def create_gradient_fade(ax, color, location='bottom', zorder=10):
101
  """
102
- Creates a fade effect at the top or bottom of the map.
 
103
  """
104
  vals = np.linspace(0, 1, 256).reshape(-1, 1)
105
  gradient = np.hstack((vals, vals))
106
-
107
  rgb = mcolors.to_rgb(color)
108
  my_colors = np.zeros((256, 4))
109
  my_colors[:, 0] = rgb[0]
110
  my_colors[:, 1] = rgb[1]
111
  my_colors[:, 2] = rgb[2]
112
-
113
  if location == 'bottom':
114
  my_colors[:, 3] = np.linspace(1, 0, 256)
115
  extent_y_start = 0
@@ -120,16 +121,29 @@ def create_gradient_fade(ax, color, location='bottom', zorder=10):
120
  extent_y_end = 1.0
121
 
122
  custom_cmap = mcolors.ListedColormap(my_colors)
123
-
 
124
  xlim = ax.get_xlim()
125
  ylim = ax.get_ylim()
 
 
126
  y_range = ylim[1] - ylim[0]
127
-
128
  y_bottom = ylim[0] + y_range * extent_y_start
129
  y_top = ylim[0] + y_range * extent_y_end
130
-
131
- ax.imshow(gradient, extent=[xlim[0], xlim[1], y_bottom, y_top],
132
- aspect='auto', cmap=custom_cmap, zorder=zorder, origin='lower')
 
 
 
 
 
 
 
 
 
 
 
133
 
134
  def get_edge_colors_by_type(G):
135
  """
@@ -272,6 +286,7 @@ def create_poster(city, country, point, dist, output_file):
272
  # Layer 3: Gradients (Top and Bottom)
273
  create_gradient_fade(ax, THEME['gradient_color'], location='bottom', zorder=10)
274
  create_gradient_fade(ax, THEME['gradient_color'], location='top', zorder=10)
 
275
 
276
  # 4. Typography using Roboto font
277
  if FONTS:
 
99
 
100
  def create_gradient_fade(ax, color, location='bottom', zorder=10):
101
  """
102
+ Creates a fade effect at the top or bottom of the map
103
+ without altering the map aspect/limits.
104
  """
105
  vals = np.linspace(0, 1, 256).reshape(-1, 1)
106
  gradient = np.hstack((vals, vals))
107
+
108
  rgb = mcolors.to_rgb(color)
109
  my_colors = np.zeros((256, 4))
110
  my_colors[:, 0] = rgb[0]
111
  my_colors[:, 1] = rgb[1]
112
  my_colors[:, 2] = rgb[2]
113
+
114
  if location == 'bottom':
115
  my_colors[:, 3] = np.linspace(1, 0, 256)
116
  extent_y_start = 0
 
121
  extent_y_end = 1.0
122
 
123
  custom_cmap = mcolors.ListedColormap(my_colors)
124
+
125
+ # Save current view/aspect so imshow can't distort the map
126
  xlim = ax.get_xlim()
127
  ylim = ax.get_ylim()
128
+ aspect = ax.get_aspect()
129
+
130
  y_range = ylim[1] - ylim[0]
 
131
  y_bottom = ylim[0] + y_range * extent_y_start
132
  y_top = ylim[0] + y_range * extent_y_end
133
+
134
+ ax.imshow(
135
+ gradient,
136
+ extent=[xlim[0], xlim[1], y_bottom, y_top],
137
+ aspect='auto',
138
+ cmap=custom_cmap,
139
+ zorder=zorder,
140
+ origin='lower'
141
+ )
142
+
143
+ # Restore view/aspect
144
+ ax.set_xlim(xlim)
145
+ ax.set_ylim(ylim)
146
+ ax.set_aspect(aspect)
147
 
148
  def get_edge_colors_by_type(G):
149
  """
 
286
  # Layer 3: Gradients (Top and Bottom)
287
  create_gradient_fade(ax, THEME['gradient_color'], location='bottom', zorder=10)
288
  create_gradient_fade(ax, THEME['gradient_color'], location='top', zorder=10)
289
+ ax.set_aspect("equal", adjustable="box")
290
 
291
  # 4. Typography using Roboto font
292
  if FONTS: