add legends and labels

This commit is contained in:
Motiejus Jakštys 2021-05-19 22:57:52 +03:00 committed by Motiejus Jakštys
parent acc76df08c
commit c64e7c1906
3 changed files with 48 additions and 32 deletions

View File

@ -102,12 +102,14 @@ mj-msc.pdf: mj-msc.tex version.inc.tex vars.inc.tex bib.bib \
define FIG_template define FIG_template
$(1).pdf: layer2img.py Makefile $(2) $(1).pdf: layer2img.py Makefile $(2)
python3 ./layer2img.py --outfile=$(1).pdf \ python3 ./layer2img.py --outfile=$(1).pdf \
$$(if $$($(1)_LEGEND),--legend=$$($(1)_LEGEND)) \
$$(if $$($(1)_WIDTHDIV),--widthdiv=$$($(1)_WIDTHDIV)) \ $$(if $$($(1)_WIDTHDIV),--widthdiv=$$($(1)_WIDTHDIV)) \
$$(if $$($(1)_QUADRANT),--quadrant=$$($(1)_QUADRANT)) \ $$(if $$($(1)_QUADRANT),--quadrant=$$($(1)_QUADRANT)) \
$$(foreach i,1 2 3, \ $$(foreach i,1 2 3, \
$$(if $$($(1)_$$(i)COLOR),--group$$(i)-color="$$($(1)_$$(i)COLOR)") \ $$(if $$($(1)_$$(i)LABEL),--g$$(i)-label="$$($(1)_$$(i)LABEL)") \
$$(if $$($(1)_$$(i)SELECT),--group$$(i)-select="$$($(1)_$$(i)SELECT)") \ $$(if $$($(1)_$$(i)COLOR),--g$$(i)-color="$$($(1)_$$(i)COLOR)") \
$$(if $$($(1)_$$(i)LINESTYLE),--group$$(i)-linestyle="$$($(1)_$$(i)LINESTYLE)") \ $$(if $$($(1)_$$(i)SELECT),--g$$(i)-select="$$($(1)_$$(i)SELECT)") \
$$(if $$($(1)_$$(i)LINESTYLE),--g$$(i)-linestyle="$$($(1)_$$(i)LINESTYLE)") \
) )
endef endef
$(foreach fig,$(FIGURES),$(eval $(call FIG_template,$(fig),.faux_test))) $(foreach fig,$(FIGURES),$(eval $(call FIG_template,$(fig),.faux_test)))
@ -271,8 +273,12 @@ salvis-wm-vw-50k_1SELECT = wm_visuals where name='salvis-vw-64'
salvis-wm-vw-50k_2SELECT = wm_visuals where name='salvis-wm-75' salvis-wm-vw-50k_2SELECT = wm_visuals where name='salvis-wm-75'
salvis-wm-vw-50k_3SELECT = wm_visuals where name='salvis' salvis-wm-vw-50k_3SELECT = wm_visuals where name='salvis'
salvis-wm-vw-50k_1COLOR = green salvis-wm-vw-50k_1COLOR = green
salvis-wm-vw-50k_1LABEL = Visvalingam--Whyatt
salvis-wm-vw-50k_2COLOR = orange salvis-wm-vw-50k_2COLOR = orange
salvis-wm-vw-50k_2LABEL = Wang--Müller
salvis-wm-vw-50k_3LINESTYLE = dotted salvis-wm-vw-50k_3LINESTYLE = dotted
salvis-wm-vw-50k_3LABEL = GRPK
salvis-wm-vw-50k_LEGEND = "lower left"
salvis-wm-vw-chaikin-50k_1SELECT = wm_visuals where name='salvis-vw-64-chaikin' salvis-wm-vw-chaikin-50k_1SELECT = wm_visuals where name='salvis-vw-64-chaikin'
salvis-wm-vw-chaikin-50k_2SELECT = wm_visuals where name='salvis-wm-75' salvis-wm-vw-chaikin-50k_2SELECT = wm_visuals where name='salvis-wm-75'

View File

@ -8,8 +8,8 @@ Accepts a few geometry fine-tuning parameters.
import argparse import argparse
import geopandas import geopandas
import psycopg2 import psycopg2
import matplotlib.pyplot as plt
from matplotlib import rc from matplotlib import rc
import matplotlib.pyplot as plt
CMAP = 'tab20c' # 'Set3' # is nice too CMAP = 'tab20c' # 'Set3' # is nice too
PSQL_CREDS = "host=127.0.0.1 dbname=osm user=osm password=osm" PSQL_CREDS = "host=127.0.0.1 dbname=osm user=osm password=osm"
@ -34,15 +34,20 @@ def inch(cm):
def parse_args(): def parse_args():
kwcolor = {'type': color, 'default': 'black'} kwcolor = {'type': color, 'default': 'black'}
parser = argparse.ArgumentParser(description=__doc__) parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--group1-select') parser.add_argument('--g1-select')
parser.add_argument('--group1-linestyle') parser.add_argument('--g1-linestyle')
parser.add_argument('--group1-color', **kwcolor) parser.add_argument('--g1-label')
parser.add_argument('--group2-select') parser.add_argument('--g1-color', **kwcolor)
parser.add_argument('--group2-linestyle') parser.add_argument('--g2-select')
parser.add_argument('--group2-color', **kwcolor) parser.add_argument('--g2-linestyle')
parser.add_argument('--group3-select') parser.add_argument('--g2-label')
parser.add_argument('--group3-linestyle') parser.add_argument('--g2-color', **kwcolor)
parser.add_argument('--group3-color', **kwcolor) parser.add_argument('--g3-select')
parser.add_argument('--g3-linestyle')
parser.add_argument('--g3-label')
parser.add_argument('--g3-color', **kwcolor)
parser.add_argument('--legend',
help="Legend location, following matplotlib rules", default='best')
parser.add_argument('--widthdiv', default=1, type=float, parser.add_argument('--widthdiv', default=1, type=float,
help="Divide the width by this number " help="Divide the width by this number "
"(useful when two images are laid horizontally " "(useful when two images are laid horizontally "
@ -68,7 +73,7 @@ def read_layer(select, width, maybe_quadrant):
return geopandas.read_postgis(sql, con=conn, geom_col='way1') return geopandas.read_postgis(sql, con=conn, geom_col='way1')
def plot_args(geom, color, maybe_linestyle): def plot_args(geom, color, maybe_linestyle, maybe_label):
if geom is None: if geom is None:
return return
@ -88,27 +93,32 @@ def plot_args(geom, color, maybe_linestyle):
r['color'] = (0, 0, 0, 0) r['color'] = (0, 0, 0, 0)
elif maybe_linestyle: elif maybe_linestyle:
r['linestyle'] = maybe_linestyle r['linestyle'] = maybe_linestyle
if maybe_label:
r['label'] = '\\normalfont %s' % maybe_label
return r return r
def main(): def main():
args = parse_args() args = parse_args()
width = TEXTWIDTH_CM / args.widthdiv width = TEXTWIDTH_CM / args.widthdiv
group1 = read_layer(args.group1_select, width, args.quadrant) g1 = read_layer(args.g1_select, width, args.quadrant)
group2 = read_layer(args.group2_select, width, args.quadrant) g2 = read_layer(args.g2_select, width, args.quadrant)
group3 = read_layer(args.group3_select, width, args.quadrant) g3 = read_layer(args.g3_select, width, args.quadrant)
c1 = plot_args(group1, args.group1_color, args.group1_linestyle) c1 = plot_args(g1, args.g1_color, args.g1_linestyle, args.g1_label)
c2 = plot_args(group2, args.group2_color, args.group2_linestyle) c2 = plot_args(g2, args.g2_color, args.g2_linestyle, args.g2_label)
c3 = plot_args(group3, args.group3_color, args.group3_linestyle) c3 = plot_args(g3, args.g3_color, args.g3_linestyle, args.g3_label)
rc('text', usetex=True) rc('text', usetex=True)
fig, ax = plt.subplots() fig, ax = plt.subplots(constrained_layout=True)
fig.set_figwidth(inch(width)) fig.set_figwidth(inch(width))
group1 is not None and group1.plot(ax=ax, linewidth=.75, **c1) g1 is not None and g1.plot(ax=ax, linewidth=.75, **c1)
group2 is not None and group2.plot(ax=ax, linewidth=.75, **c2) g2 is not None and g2.plot(ax=ax, linewidth=.75, **c2)
group3 is not None and group3.plot(ax=ax, linewidth=.75, **c3) g3 is not None and g3.plot(ax=ax, linewidth=.75, **c3)
ax.legend(loc=args.legend, frameon=False)
ax.axis('off') ax.axis('off')
ax.margins(0, 0) ax.margins(0, 0)
if args.outfile: if args.outfile:

View File

@ -113,11 +113,11 @@
\end{abstract} \end{abstract}
\newpage \clearpage
\tableofcontents \tableofcontents
\listoffigures \listoftables
\listoflistings \listoflistings
\newpage \newpage