IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Python Discussion :

Nommer les axes d'un graphique reportlab


Sujet :

Python

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Curieux
    Inscrit en
    Avril 2020
    Messages
    114
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Seine et Marne (Île de France)

    Informations professionnelles :
    Activité : Curieux
    Secteur : Bâtiment

    Informations forums :
    Inscription : Avril 2020
    Messages : 114
    Par défaut Nommer les axes d'un graphique reportlab
    Bonjour,
    Je tente péniblement à produire un graphique via Reportlab, un LinePlot() et je bloque sur l'ajout des noms des axes. J'ai réussi une petite fonction qui me produit un graphique plus ou moins maitrisé grâce à la documentation, et à trouver un exemple dans une class. Je me trouve bien embêté car mon niveau ne me permet pas de travailler cette class.
    Et ne comprenant pas comment fonctionne cette ligne je n'arrive pas à l'adapter à la fonction.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    self._add(self,Label(),name='XLabel',validate=None,desc="The label on the horizontal axis")
    Je pense aussi que ReportLab graphique en version à la main est pas des plus simple, voici ma base de test.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    from reportlab.graphics.charts.lineplots import LinePlot
    from reportlab.graphics.shapes import Drawing, _DrawingEditorMixin
    from reportlab.lib.validators import Auto
    from reportlab.graphics.widgets.markers import makeMarker
    from reportlab.pdfbase.pdfmetrics import stringWidth, EmbeddedType1Face, registerTypeFace, Font, registerFont
    from reportlab.graphics.charts.axes import XValueAxis, YValueAxis, AdjYValueAxis, NormalDateXValueAxis
    from reportlab.platypus import Paragraph, Spacer, SimpleDocTemplate, Table
    from reportlab.lib.pagesizes import A4
    from reportlab.lib import colors
    from reportlab.graphics.shapes import Drawing
     
    contenue    = []
     
    def graph1():
        "Sample drawing, xvalue/yvalue axes, y connected at left of x."
        drawing = Drawing(400, 200)
        chart = LinePlot()
        chart2 = LinePlot()
        # line styles
        chart.lines[0].strokeColor = colors.green
        chart.lines[0].symbol = makeMarker(None)
        chart.lines[0].symbol.size        = 2
        chart.lines[0].symbol.angle       = 15
        chart.data = [[(1, 0), (2, 5.29), (3,5.2),(4,2),(5,4.6),(8,3)]]
        #chart.xValueAxis.setPosition(50, 50, 300)
        chart.xValueAxis.visibleGrid           = 1
     
        chart.yValueAxis = YValueAxis()
        chart.yValueAxis.setPosition(50, 50, 125)
        chart.yValueAxis.joinAxisMode = 'left'
        #chart.yValueAxis.configure(chart.data)
        drawing.add(chart)
     
        chart2.data = [[(1, 0.391), (2, 1.29), (3, 3.298),(4,2.335),(5,0),(8,0)]]
        #chart2.data = [[(0,0)]]
        #chart2.yValueAxis.setPosition(50, 50, 125)
        chart2.xValueAxis.visible           = 0
        chart2.yValueAxis.joinAxisMode = 'right'
        # y2 axis
        chart2.yValueAxis.visibleGrid           = 1
        chart2.yValueAxis.gridStrokeWidth       = 0.15
        chart2.yValueAxis.gridStrokeColor       = colors.darkgrey
        chart2.yValueAxis.visibleAxis           = 1
    #    chart.yValueAxis.labels.fontSize       = fontSize -1
        chart2.yValueAxis.labels.textAnchor = 'start'
        chart2.yValueAxis.labels.boxAnchor = 'w'
        chart2.yValueAxis.labels.angle = 0
        chart2.yValueAxis.labels.dx = 5
        chart2.yValueAxis.labels.dy = 0
     
        chart2.yValueAxis.strokeWidth           = 0.45
        chart2.yValueAxis.visible               = 1
        chart2.yValueAxis.labels.rightPadding   = 2
        chart2.yValueAxis.rangeRound            ='both'
        chart2.yValueAxis.tickLeft             = -2.5
        chart2.yValueAxis.minimumTickSpacing    = 8
        chart2.yValueAxis.maximumTicks          = 10
        chart2.yValueAxis.visibleSubTicks       = 1
        chart2.yValueAxis.subTickHi             = 0
        chart2.yValueAxis.subTickLo             = 1
        chart2.yValueAxis.subTickNum            = 1
        chart2.yValueAxis.forceZero             = 0
        chart2.yValueAxis.avoidBoundFrac        = 0.1
        drawing.add(chart2)
        return drawing 
     
    class Graph():
     
        def __init__(self,width=200,height=150,*args,**kw):
            Drawing.__init__(self,width,height,*args,**kw)
            self._add(self,LinePlot(),name='chart',validate=None,desc="The main chart")
            self.chart.width      = 115
            self.chart.height     = 80
            self.chart.x          = 30
            self.chart.y          = 40
            self.chart.lines[0].strokeColor = color01
            self.chart.lines[1].strokeColor = color02
            self.chart.lines[2].strokeColor = color03
            self.chart.lines[3].strokeColor = color04
            self.chart.lines[4].strokeColor = color05
            self.chart.lines[5].strokeColor = color06 
            self.chart.lines[6].strokeColor = color07
            self.chart.lines[7].strokeColor = color08 
            self.chart.lines[8].strokeColor = color09
            self.chart.lines[9].strokeColor = color10
            self.chart.lines[0].symbol = makeMarker('FilledSquare')
            self.chart.lines[1].symbol = makeMarker('FilledDiamond') 
            self.chart.lines[2].symbol = makeMarker('FilledStarFive')
            self.chart.lines[3].symbol = makeMarker('FilledTriangle')
            self.chart.lines[4].symbol = makeMarker('FilledCircle') 
            self.chart.lines[5].symbol = makeMarker('FilledPentagon')
            self.chart.lines[6].symbol = makeMarker('FilledStarSix') 
            self.chart.lines[7].symbol = makeMarker('FilledHeptagon')
            self.chart.lines[8].symbol = makeMarker('FilledOctagon')
            self.chart.lines[9].symbol = makeMarker('FilledCross')
            self.chart.fillColor       = backgroundGrey 
            self.chart.lineLabels.fontName  = 'Helvetica'
            self.chart.xValueAxis.labels.fontName       = 'Helvetica' 
            self.chart.xValueAxis.labels.fontSize       = 7
            self.chart.xValueAxis.forceZero             = 0
            self.chart.data             = [((0, 50), (100,100), (200,200), (250,210), (300,300), (400,500)), ((0, 150), (100,200), (200,300), (250,200), (300,400), (400, 600))]
            self.chart.xValueAxis.avoidBoundFrac           = 1
            self.chart.xValueAxis.gridEnd                  = 115
            self.chart.xValueAxis.tickDown                 = 3
            self.chart.xValueAxis.visibleGrid              = 1 
            self.chart.yValueAxis.tickLeft              = 3 
            self.chart.yValueAxis.labels.fontName       = 'Helvetica'
            self.chart.yValueAxis.labels.fontSize       = 7
            self._add(self,Label(),name='Title',validate=None,desc="The title at the top of the chart")
            self.Title.fontName   = 'Helvetica-Bold'
            self.Title.fontSize   = 7
            self.Title.x          = 100
            self.Title.y          = 135
            self.Title._text      = 'Chart Title'
            self.Title.maxWidth   = 180
            self.Title.height     = 20
            self.Title.textAnchor ='middle'
            self._add(self,Legend(),name='Legend',validate=None,desc="The legend or key for the chart")
            self.Legend.colorNamePairs = [(color01, 'Widgets'), (color02, 'Sprockets')]
            self.Legend.fontName       = 'Helvetica'
            self.Legend.fontSize       = 7
            self.Legend.x              = 153 
            self.Legend.y              = 85 
            self.Legend.dxTextSpace    = 5
            self.Legend.dy             = 5
            self.Legend.dx             = 5
            self.Legend.deltay         = 5 
            self.Legend.alignment      ='right'
            self._add(self,Label(),name='XLabel',validate=None,desc="The label on the horizontal axis")
            self.XLabel.fontName       = 'Helvetica'
            self.XLabel.fontSize       = 7
            self.XLabel.x              = 85
            self.XLabel.y              = 10
            self.XLabel.textAnchor     ='middle'
            self.XLabel.maxWidth       = 100 
            self.XLabel.height         = 20
            self.XLabel._text          = "X Axis"
            self._add(self,Label(),name='YLabel',validate=None,desc="The label on the vertical axis")
            self.YLabel.fontName       = 'Helvetica'
            self.YLabel.fontSize       = 7
            self.YLabel.x              = 12
            self.YLabel.y              = 80
            self.YLabel.angle          = 90
            self.YLabel.textAnchor     ='middle' 
            self.YLabel.maxWidth       = 100 
            self.YLabel.height         = 20
            self.YLabel._text          = "Y Axis" 
            self.chart.yValueAxis.forceZero           = 1
            self.chart.xValueAxis.forceZero           = 1
            self._add(self,0,name='preview',validate=None,desc=None)
     
     
    contenue.append(Graph())
    contenue.append(graph1())
    doc = SimpleDocTemplate('test1.pdf',
                            pagesize = A4,
                            title = 'Premier test',
                            author = 'Moi',
                            topMargin=4,
                            showBoundary = 0)
    doc.build(contenue)
    Merci

  2. #2
    Expert éminent
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 741
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 741
    Par défaut
    Salut,

    Citation Envoyé par Aelurus_ Voir le message
    Je pense aussi que ReportLab graphique en version à la main est pas des plus simple
    Quand c'est compliqué, il y a des exemples prêts à emporter qu'on peut adapter.
    Pour reportlab, la mine est ici.

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  3. #3
    Membre confirmé
    Homme Profil pro
    Curieux
    Inscrit en
    Avril 2020
    Messages
    114
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Seine et Marne (Île de France)

    Informations professionnelles :
    Activité : Curieux
    Secteur : Bâtiment

    Informations forums :
    Inscription : Avril 2020
    Messages : 114
    Par défaut
    Merci Wiztricks, pour le coup la mine je l'ai visitée, fouillée, retournée ^^ sans vraiment trouver une solution exploitable. Il y a certes plein d'exemple pour les graphs en barre, camembert, mais les arguments n'est pas transposable à un line plot. Et dans aucun de leur exemple de lineplot il n'y a d'axes nommés

  4. #4
    Expert éminent
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 741
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 741
    Par défaut
    Salut,

    Citation Envoyé par Aelurus_ Voir le message
    Et dans aucun de leur exemple de lineplot il n'y a d'axes nommés
    Dans cet exemple là il y a ce que j'appellerai "axes" nommés.
    Mais vous attendez peut être autre chose.

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  5. #5
    Membre confirmé
    Homme Profil pro
    Curieux
    Inscrit en
    Avril 2020
    Messages
    114
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Seine et Marne (Île de France)

    Informations professionnelles :
    Activité : Curieux
    Secteur : Bâtiment

    Informations forums :
    Inscription : Avril 2020
    Messages : 114
    Par défaut
    J'ai bien vu aussi, c'est effectivement cela que j'entend par axes nommés.

    mais
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    self.chart.xTitleText           = 'Year'
    me donne AttributeError: Illegal attribute 'xTitleText' in class LinePlot. et je ne trouve pas son équivalent dans la class linePlot.

    Ensuite le gros avantage de cette librairie est de pouvoir inclure des graphiques directement dans le PDF, avec une taille de police indépendante de la résolution et taille du graphique. Les résultats sont très propres mais c'est un peu une usine à gaz.

  6. #6
    Membre confirmé
    Homme Profil pro
    Curieux
    Inscrit en
    Avril 2020
    Messages
    114
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Seine et Marne (Île de France)

    Informations professionnelles :
    Activité : Curieux
    Secteur : Bâtiment

    Informations forums :
    Inscription : Avril 2020
    Messages : 114
    Par défaut
    Je trouve cette solution,
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    self._add(self,Label(),name='Title',validate=None,desc="The title at the top of the chart")
    que je n'arrive pas à sortir de la class et à l'adapter dans une fonction.
    Je vais donc essayer de manipuler la class.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Inverser les axes d'un graphique sur Excel
    Par ploup dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 03/02/2009, 17h44
  2. Réponses: 1
    Dernier message: 23/12/2008, 11h20
  3. Comment modifier les axes d'un graphique
    Par AC88mm dans le forum MATLAB
    Réponses: 3
    Dernier message: 03/04/2007, 10h34
  4. [CR XI] format numérique sur les axes d'un graphique
    Par kikidrome dans le forum SAP Crystal Reports
    Réponses: 5
    Dernier message: 23/03/2007, 15h20
  5. Mettre des données string sur les axes d'un graphique
    Par Aurore_atmo dans le forum MATLAB
    Réponses: 2
    Dernier message: 06/07/2006, 11h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo