Commit fd62ba0a authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Merge branch '14-domain-table' into 'master'

14 domain table

* Update the database schema by adding the table `domains`.
* Add the module `matplotlib_tools`.
* Add the script `lbfr_report.py`
* Close #14 

See merge request !17
parents 31d61aed 88085343
docs/db_schema/database.png

130 KB | W: | H:

docs/db_schema/database.png

127 KB | W: | H:

docs/db_schema/database.png
docs/db_schema/database.png
docs/db_schema/database.png
docs/db_schema/database.png
  • 2-up
  • Swipe
  • Onion skin
<?xml version="1.0" encoding="utf-8" ?><sql><datatypes db="web2py">
<?xml version="1.0" encoding="utf-8" ?>
<!-- SQL XML created by WWW SQL Designer, https://github.com/ondras/wwwsqldesigner/ -->
<!-- Active URL: file:///home/legac/mywap/wwwsqldesigner/index.html -->
<sql>
<datatypes db="web2py">
<group label="Numeric" color="rgb(238,238,170)">
<type label="Integer" length="1" sql="integer" re="INTEGER" quote=""/>
<type label="Double precision" length="1" sql="double" re="DOUBLE" quote=""/>
......@@ -22,4 +26,320 @@
<type label="Upload" length="0" sql="upload" quote="'"/>
<type label="Password" length="0" sql="password" quote="'"/>
</group>
</datatypes><table x="303" y="21" name="people"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="first_name" null="0" autoincrement="0"><datatype>string</datatype></row><row name="last_name" null="0" autoincrement="0"><datatype>string</datatype></row><row name="initials" null="0" autoincrement="0"><datatype>string</datatype></row><row name="birth_date" null="1" autoincrement="0"><datatype>date</datatype></row><row name="note" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="302" y="174" name="teams"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="team" null="0" autoincrement="0"><datatype>string</datatype></row><row name="domain" null="1" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="303" y="285" name="projects"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="project" null="0" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="618" y="19" name="people_categories"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="code" null="0" autoincrement="0"><datatype>string</datatype></row><row name="category" null="0" autoincrement="0"><datatype>string</datatype></row><row name="definition" null="1" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="452" y="71" name="history"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="id_people" null="0" autoincrement="0"><datatype>integer</datatype><relation table="people" row="id" /></row><row name="id_teams" null="0" autoincrement="0"><datatype>integer</datatype><relation table="teams" row="id" /></row><row name="id_projects" null="0" autoincrement="0"><datatype>integer</datatype><relation table="projects" row="id" /></row><row name="id_people_categories" null="0" autoincrement="0"><datatype>integer</datatype><relation table="people_categories" row="id" /></row><row name="id_fundings" null="0" autoincrement="0"><datatype>integer</datatype><relation table="fundings" row="id" /></row><row name="id_objects" null="0" autoincrement="0"><datatype>integer</datatype><relation table="objects" row="id" /></row><row name="id_object_categories" null="0" autoincrement="0"><datatype>integer</datatype><relation table="object_categories" row="id" /></row><row name="id_events" null="0" autoincrement="0"><datatype>integer</datatype><relation table="events" row="id" /></row><row name="start_date" null="0" autoincrement="0"><datatype>date</datatype></row><row name="end_date" null="1" autoincrement="0"><datatype>date</datatype></row><row name="percentage" null="1" autoincrement="0"><datatype>integer</datatype></row><row name="note" null="0" autoincrement="0"><datatype>text</datatype></row><row name="data" null="1" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="633" y="149" name="fundings"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="agency" null="0" autoincrement="0"><datatype>string</datatype></row><row name="definition" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="638" y="266" name="events"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="event" null="0" autoincrement="0"><datatype>string</datatype></row><row name="definitiion" null="1" autoincrement="0"><datatype>text</datatype></row><row name="data" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="827" y="22" name="lists"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="name" null="0" autoincrement="0"><datatype>string</datatype></row><row name="title" null="1" autoincrement="0"><datatype>string</datatype></row><row name="conditions" null="1" autoincrement="0"><datatype>text</datatype></row><row name="group_field" null="1" autoincrement="0"><datatype>string</datatype></row><row name="sorters" null="1" autoincrement="0"><datatype>integer</datatype></row><row name="columns" null="0" autoincrement="0"><datatype>text</datatype></row><row name="features" null="1" autoincrement="0"><datatype>text</datatype></row><row name="definition" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="934" y="193" name="metrics2d"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="name" null="0" autoincrement="0"><datatype>string</datatype></row><row name="title" null="1" autoincrement="0"><datatype>string</datatype></row><row name="conditions" null="1" autoincrement="0"><datatype>text</datatype></row><row name="group_field_x" null="0" autoincrement="0"><datatype>string</datatype></row><row name="group_field_y" null="0" autoincrement="0"><datatype>string</datatype></row><row name="metric_field_z" null="0" autoincrement="0"><datatype>string</datatype></row><row name="aggregate_z" null="0" autoincrement="0"><datatype>string</datatype></row><row name="definition" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="1065" y="22" name="graphs"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="name" null="0" autoincrement="0"><datatype>string</datatype></row><row name="title" null="1" autoincrement="0"><datatype>string</datatype></row><row name="report_type" null="0" autoincrement="0"><datatype>string</datatype></row><row name="report_name" null="1" autoincrement="0"><datatype>string</datatype></row><row name="plot" null="0" autoincrement="0"><datatype>text</datatype></row><row name="definition" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="929" y="19" name="metrics1d"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="name" null="0" autoincrement="0"><datatype>string</datatype></row><row name="title" null="1" autoincrement="0"><datatype>string</datatype></row><row name="conditions" null="1" autoincrement="0"><datatype>text</datatype></row><row name="group_field" null="1" autoincrement="0"><datatype>string</datatype></row><row name="columns" null="0" autoincrement="0"><datatype>text</datatype></row><row name="definition" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="616" y="391" name="object_categories"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="code" null="0" autoincrement="0"><datatype>string</datatype></row><row name="category" null="0" autoincrement="0"><datatype>string</datatype></row><row name="definition" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="324" y="372" name="objects"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="reference" null="1" autoincrement="0"><datatype>string</datatype></row><row name="serial_number" null="0" autoincrement="0"><datatype>string</datatype></row><row name="batch_number" null="0" autoincrement="0"><datatype>string</datatype></row><row name="note" null="0" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table></sql>
\ No newline at end of file
</datatypes><table x="303" y="21" name="people">
<row name="id" null="0" autoincrement="1">
<datatype>integer</datatype>
</row>
<row name="first_name" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="last_name" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="initials" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="birth_date" null="1" autoincrement="0">
<datatype>date</datatype>
<default>NULL</default></row>
<row name="note" null="1" autoincrement="0">
<datatype>text</datatype>
<default>NULL</default></row>
<key type="PRIMARY" name="">
<part>id</part>
</key>
</table>
<table x="302" y="183" name="teams">
<row name="id" null="0" autoincrement="1">
<datatype>integer</datatype>
</row>
<row name="team" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<key type="PRIMARY" name="">
<part>id</part>
</key>
</table>
<table x="303" y="285" name="projects">
<row name="id" null="0" autoincrement="1">
<datatype>integer</datatype>
</row>
<row name="project" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<key type="PRIMARY" name="">
<part>id</part>
</key>
</table>
<table x="618" y="19" name="people_categories">
<row name="id" null="0" autoincrement="1">
<datatype>integer</datatype>
</row>
<row name="code" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="category" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="definition" null="1" autoincrement="0">
<datatype>string</datatype>
<default>NULL</default></row>
<key type="PRIMARY" name="">
<part>id</part>
</key>
</table>
<table x="447" y="100" name="history">
<row name="id" null="0" autoincrement="1">
<datatype>integer</datatype>
</row>
<row name="id_people" null="0" autoincrement="0">
<datatype>integer</datatype>
<relation table="people" row="id" />
</row>
<row name="id_domains" null="1" autoincrement="0">
<datatype>integer</datatype>
<default>NULL</default><relation table="domains" row="id" />
</row>
<row name="id_teams" null="0" autoincrement="0">
<datatype>integer</datatype>
<relation table="teams" row="id" />
</row>
<row name="id_projects" null="0" autoincrement="0">
<datatype>integer</datatype>
<relation table="projects" row="id" />
</row>
<row name="id_people_categories" null="0" autoincrement="0">
<datatype>integer</datatype>
<relation table="people_categories" row="id" />
</row>
<row name="id_fundings" null="0" autoincrement="0">
<datatype>integer</datatype>
<relation table="fundings" row="id" />
</row>
<row name="id_objects" null="0" autoincrement="0">
<datatype>integer</datatype>
<relation table="objects" row="id" />
</row>
<row name="id_object_categories" null="0" autoincrement="0">
<datatype>integer</datatype>
<relation table="object_categories" row="id" />
</row>
<row name="id_events" null="0" autoincrement="0">
<datatype>integer</datatype>
<relation table="events" row="id" />
</row>
<row name="start_date" null="0" autoincrement="0">
<datatype>date</datatype>
</row>
<row name="end_date" null="1" autoincrement="0">
<datatype>date</datatype>
<default>NULL</default></row>
<row name="percentage" null="1" autoincrement="0">
<datatype>integer</datatype>
<default>NULL</default></row>
<row name="note" null="0" autoincrement="0">
<datatype>text</datatype>
</row>
<row name="data" null="1" autoincrement="0">
<datatype>string</datatype>
<default>NULL</default></row>
<key type="PRIMARY" name="">
<part>id</part>
</key>
</table>
<table x="633" y="149" name="fundings">
<row name="id" null="0" autoincrement="1">
<datatype>integer</datatype>
</row>
<row name="agency" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="definition" null="1" autoincrement="0">
<datatype>text</datatype>
<default>NULL</default></row>
<key type="PRIMARY" name="">
<part>id</part>
</key>
</table>
<table x="611" y="393" name="events">
<row name="id" null="0" autoincrement="1">
<datatype>integer</datatype>
</row>
<row name="event" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="definitiion" null="1" autoincrement="0">
<datatype>text</datatype>
<default>NULL</default></row>
<row name="data" null="1" autoincrement="0">
<datatype>text</datatype>
<default>NULL</default></row>
<key type="PRIMARY" name="">
<part>id</part>
</key>
</table>
<table x="827" y="22" name="lists">
<row name="id" null="0" autoincrement="1">
<datatype>integer</datatype>
</row>
<row name="name" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="title" null="1" autoincrement="0">
<datatype>string</datatype>
<default>NULL</default></row>
<row name="conditions" null="1" autoincrement="0">
<datatype>text</datatype>
<default>NULL</default></row>
<row name="group_field" null="1" autoincrement="0">
<datatype>string</datatype>
<default>NULL</default></row>
<row name="sorters" null="1" autoincrement="0">
<datatype>integer</datatype>
<default>NULL</default></row>
<row name="columns" null="0" autoincrement="0">
<datatype>text</datatype>
</row>
<row name="features" null="1" autoincrement="0">
<datatype>text</datatype>
<default>NULL</default></row>
<row name="definition" null="1" autoincrement="0">
<datatype>text</datatype>
<default>NULL</default></row>
<key type="PRIMARY" name="">
<part>id</part>
</key>
</table>
<table x="934" y="193" name="metrics2d">
<row name="id" null="0" autoincrement="1">
<datatype>integer</datatype>
</row>
<row name="name" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="title" null="1" autoincrement="0">
<datatype>string</datatype>
<default>NULL</default></row>
<row name="conditions" null="1" autoincrement="0">
<datatype>text</datatype>
<default>NULL</default></row>
<row name="group_field_x" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="group_field_y" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="metric_field_z" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="aggregate_z" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="definition" null="1" autoincrement="0">
<datatype>text</datatype>
<default>NULL</default></row>
<key type="PRIMARY" name="">
<part>id</part>
</key>
</table>
<table x="1065" y="22" name="graphs">
<row name="id" null="0" autoincrement="1">
<datatype>integer</datatype>
</row>
<row name="name" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="title" null="1" autoincrement="0">
<datatype>string</datatype>
<default>NULL</default></row>
<row name="report_type" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="report_name" null="1" autoincrement="0">
<datatype>string</datatype>
<default>NULL</default></row>
<row name="plot" null="0" autoincrement="0">
<datatype>text</datatype>
</row>
<row name="definition" null="1" autoincrement="0">
<datatype>text</datatype>
<default>NULL</default></row>
<key type="PRIMARY" name="">
<part>id</part>
</key>
</table>
<table x="929" y="19" name="metrics1d">
<row name="id" null="0" autoincrement="1">
<datatype>integer</datatype>
</row>
<row name="name" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="title" null="1" autoincrement="0">
<datatype>string</datatype>
<default>NULL</default></row>
<row name="conditions" null="1" autoincrement="0">
<datatype>text</datatype>
<default>NULL</default></row>
<row name="group_field" null="1" autoincrement="0">
<datatype>string</datatype>
<default>NULL</default></row>
<row name="columns" null="0" autoincrement="0">
<datatype>text</datatype>
</row>
<row name="definition" null="1" autoincrement="0">
<datatype>text</datatype>
<default>NULL</default></row>
<key type="PRIMARY" name="">
<part>id</part>
</key>
</table>
<table x="626" y="258" name="object_categories">
<row name="id" null="0" autoincrement="1">
<datatype>integer</datatype>
</row>
<row name="code" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="category" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="definition" null="1" autoincrement="0">
<datatype>text</datatype>
<default>NULL</default></row>
<key type="PRIMARY" name="">
<part>id</part>
</key>
</table>
<table x="309" y="365" name="objects">
<row name="id" null="0" autoincrement="1">
<datatype>integer</datatype>
</row>
<row name="reference" null="1" autoincrement="0">
<datatype>string</datatype>
<default>NULL</default></row>
<row name="serial_number" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="batch_number" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="note" null="0" autoincrement="0">
<datatype>text</datatype>
</row>
<key type="PRIMARY" name="">
<part>id</part>
</key>
</table>
<table x="466" y="18" name="domains">
<row name="id" null="1" autoincrement="1">
<datatype>integer</datatype>
<default>NULL</default></row>
<row name="domain" null="0" autoincrement="0">
<datatype>string</datatype>
<default>'NULL'</default></row>
<key type="PRIMARY" name="">
<part>id</part>
</key>
</table>
</sql>
......@@ -94,6 +94,7 @@
'Documentations': 'Documentations',
'Domain': 'Domaine',
'Domaine': 'Domaine',
'domains': 'domaines',
'Duration': 'Durée',
'E-mail': 'E-mail',
'end': 'fin',
......
......@@ -51,6 +51,7 @@ year = now.year
tables = ['auth_group',
'auth_membership',
'auth_user',
'domains',
'events',
'fundings',
'graphs',
......
# -*- coding: utf-8 -*-
""" domains
"""
db.define_table("domains",
Field("domain", "string", length=255, notnull=True, unique=True),
migrate="domains.table")
db.domains._before_delete.append(INHIBIT_CASCADE_DELETE)
db.domains._before_delete.append(dbui.INHIBIT_DELETE_UNDEF)
db.domains._before_update.append(dbui.INHIBIT_UPDATE_UNDEF)
......@@ -4,7 +4,6 @@
"""
db.define_table("teams",
Field("team", "string", length=255, notnull=True, unique=True),
Field("domain", "string", length=255),
migrate="teams.table")
db.teams._before_delete.append(INHIBIT_CASCADE_DELETE)
......
......@@ -4,6 +4,7 @@
"""
db.define_table("history",
Field("id_events", "reference events", default=undef_id, label='Event'),
Field("id_domains", "reference domains", default=undef_id, label='Domain'),
Field("id_teams", "reference teams", default=undef_id, label='Team'),
Field("id_projects", "reference projects", default=undef_id, label='Project'),
Field("id_fundings", "reference fundings", default=undef_id, label='Funding'),
......
# -*- coding: utf-8 -*-
""" teams
"""
#-------------------------------------------------------------------------------
#
# FIELDS CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# FORM CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# GRID CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# STORE CONFIGURATiON
#
#-------------------------------------------------------------------------------
storeModifier = dbui.StoreModifier('domains')
storeModifier.orderby(db.domains.domain)
\ No newline at end of file
......@@ -28,7 +28,8 @@ fieldsModifier.configure_field('note', height=150)
#
#-------------------------------------------------------------------------------
formModifier = dbui.FormModifier('history')
formModifier.merge_fields('id_teams',
formModifier.merge_fields('id_domains',
'id_teams',
'id_projects',
'id_fundings',
title=T('Metadata'))
......@@ -63,12 +64,14 @@ gridModifier = dbui.GridModifier('history')
gridModifier.configure(plugins=['pGridPaging'])
gridModifier.hide_columns('data',
'id_domains',
'id_object_categories',
'id_people_categories',
'note',
'percentage')
gridModifier.append_filter(('id_events', '==', T('is equal to')))
gridModifier.append_filter(('id_domains', '==', T('is equal to')))
gridModifier.append_filter(('id_teams', '==', T('is equal to')))
gridModifier.append_filter(('id_projects', '==', T('is equal to')))
gridModifier.append_filter(('id_fundings', '==', T('is equal to')))
......
......@@ -4,6 +4,10 @@
Insert defaults values in the tables
"""
if not db(db.domains.id).count():
db.domains.insert(id=undef_id,
domain=undef)
if not db(db.events.id).count():
db.events.insert(id=undef_id,
event=undef,
......
......@@ -7,6 +7,7 @@ tp_data = T("The field history.data contains the given value.")
virtdb.define_table('selector',
Field('year_start', 'integer', default=year),
Field('year_end', 'integer'),
Field('id_domains', 'reference domains', label=T('Domain')),
Field('id_teams', 'reference teams', label=T('Team')),
Field('id_projects', 'reference projects', label=T('Project')),
Field('id_fundings', 'reference fundings', label=T('Funding')),
......@@ -28,6 +29,7 @@ IS_IN_DB(db, 'alias_people_categories.category')
virtdb.selector.id_people_code.requires = \
IS_IN_DB(db, 'people_categories.code')
virtdb.selector.id_domains.requires = IS_IN_DB(db, 'domains.domain')
virtdb.selector.id_fundings.requires = IS_IN_DB(db, 'fundings.agency')
virtdb.selector.id_projects.requires = IS_IN_DB(db, 'projects.project')
virtdb.selector.id_teams.requires = IS_IN_DB(db, 'teams.team')
......@@ -46,6 +48,7 @@ mytype = 'xcomboboxuserreset'
text = T('select...')
fieldsModifier.configure_field('id_categories', emptyText=text, xtype=mytype)
fieldsModifier.configure_field('id_domains', emptyText=text, xtype=mytype)
fieldsModifier.configure_field('id_fundings', emptyText=text, xtype=mytype)
fieldsModifier.configure_field('id_object_categories', emptyText=text, xtype=mytype)
fieldsModifier.configure_field('id_object_code', emptyText=text, xtype=mytype)
......
......@@ -78,6 +78,7 @@ cfgNode.add_child(T('the graphs'), to_grid('graphs'))
#
#-------------------------------------------------------------------------------
metaNode = Node(T('Metadata'))
metaNode.add_child(T('domains'), to_grid('domains'))
metaNode.add_child(T('fundings'), to_grid('fundings'))
metaNode.add_child(T('teams'), to_grid('teams'))
metaNode.add_child(T('projects'), to_grid('projects'))
......
......@@ -34,22 +34,121 @@ def create_pdf(base):
return PdfPages(fn)
def header_footer(fig, title):
def header_footer(fig, title, timestamp=False):
"""write the header_footer and the footer.
Args:
ax (matplotlib.Figure):
title (str):
timestamp (bool):
"""
msg = NOW.strftime("%b %d, %Y %H:%M\nday %j -- week %W")
fig.text(0.05, 0.9, title, fontsize=14)
fig.text(0.94, 0.89, msg, fontsize=8, horizontalalignment='right')
if timestamp:
msg = NOW.strftime("%b %d, %Y %H:%M\nday %j -- week %W")
fig.text(0.94, 0.89, msg, fontsize=8, horizontalalignment='right')
fig.text(0.94, 0.04, fig.number, fontsize=10, horizontalalignment='right')
def plot_references(ax, lines, values, xpos, stacked=False):
"""Plot reference markers.
Args:
ax (matplotlib.Axes):
lines (list):
values (list): reference value per line
xpos (float):
stacked (bool)
"""
legend = ax.get_legend()
texts = [el.get_text() for el in legend.get_texts()]
value = 0.
mycolor = "black"
for line in lines:
i = texts.index(line)
if stacked:
value += values[i]
else:
value = values[i]
ax.plot(xpos,
value,
color=mycolor,
marker="<",
markeredgecolor=mycolor,
markersize=5,
transform=ax.transData)
def plot_values(ax, series, fmt="%.0f",
fontsize=8.,
maxseries=None,
percentage=0.10,
xoffset=0,
yoffset=-10,
zero=1E-05,
**kwargs):
"""plot values in bar graph.
Args:
ax (matplotlib.Axes):
series (pandas.Series):
fmt (str):
fontsize (float): fontsize for the text.
maxseries (float): maximum of the serie. The maximum of the serie is
computed by the function and used to determined the threshld.
In some case, it is usefull to specified a value.
percentage (float): yoffset is applied if value is a threshold.
The threshold is computed as percentage*max(series).
Otherwise the value is written above the bar.
xoffset (float): offset with respect to the center of the bar in
data coordinate.
yoffset (int): offset of the text with respect to the top of the bar
in the display coordinate.
zero (float): value below the threhols is not displayed
keyward arguments:
those of the matplotlib.text.Text
"""
ndata = len(series)
# fontsize depend on the number of data
fsize = (fontsize if ndata <= 15 else fontsize * sqrt(15. / ndata))
default = dict(color="0.4", fontsize=fsize, horizontalalignment="center")
default.update(kwargs)
# trans formation go to frma the transData to the display coordinate
# and vice versa
ftrans = ax.transData.transform
finv = ax.transData.inverted().transform
# plot values
if maxseries is None:
maxseries = max(series)
cut = round( maxseries * percentage)