Results 1 to 1 of 1

Thread: QWTPlot x-axis labels with float spacing

  1. #1
    Join Date
    May 2011
    Posts
    1
    Qt products
    Platforms
    Windows

    Default QWTPlot x-axis labels with float spacing

    Hi there,

    I have a QwtPlot where I plotted 5 groups of histograms and an average line above.
    To label the different groups individually by quarters (e.g. Q1/2010, Q2/2010, Q3/2010, Q4/2010, Q1/2011) I used for the x-axis:

    Qt Code:
    1. plot.setAxisMaxMinor(QwtPlot.xBottom, 0)
    2. plot.setAxisMaxMajor(QwtPlot.xBottom, len(labels))
    3. plot.axisScaleDraw(QwtPlot.xBottom).enableComponent(QwtScaleDraw.Backbone, 1)
    4. plot.axisScaleDraw(QwtPlot.xBottom).enableComponent(QwtScaleDraw.Ticks, 1)
    5. plot.axisScaleDraw(QwtPlot.xBottom).enableComponent(QwtScaleDraw.Labels, 1)
    6.  
    7. plot.setAxisScaleDraw(QwtPlot.xBottom, DiscreteAxisScaleDraw(labels))
    8.  
    9. # ####################################################################
    10. # draw labels for discrete attributes
    11. class DiscreteAxisScaleDraw(QwtScaleDraw):
    12. def __init__(self, labels):
    13. apply(QwtScaleDraw.__init__, (self,))
    14. self.labels = labels
    15.  
    16.  
    17. def label(self, value):
    18. index = int(round(value))
    19. if index != value: return QwtText("") # if value not an integer value return ""
    20. if index >= len(self.labels) or index < 0: return QwtText("")
    21. return QwtText(str(self.labels[index]))
    To copy to clipboard, switch view to plain text mode 

    However, when rescaling the x-axis by
    Qt Code:
    1. plot.setAxisScale(QwtPlot.xBottom, -0.2, 20,4.2)
    To copy to clipboard, switch view to plain text mode 

    as to set the ticks at the beginning of each of the histogram groups,
    the labels disappear apart from the first one (see figure). I guess this is due to the fact that the ticks are placed at a non-integer distance (step size 4.2).
    When using a step size =1, the labels are visible but not at the right position due to the integer spacing.
    Does anyone know how to solve this problem?

    Thanks a lot in advance.
    Attached Images Attached Images

Similar Threads

  1. Labels on axis.
    By eugene in forum Qwt
    Replies: 5
    Last Post: 6th August 2010, 14:30
  2. Replies: 1
    Last Post: 16th March 2010, 16:23
  3. Y-Axis Scale Spacing - Newbie Question
    By Rick108 in forum Qwt
    Replies: 3
    Last Post: 13th October 2009, 09:20
  4. Axis with more labels
    By rakkar in forum Qwt
    Replies: 1
    Last Post: 11th October 2009, 10:26
  5. Relocating axis labels
    By malcom2073 in forum Qwt
    Replies: 0
    Last Post: 9th May 2008, 14:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.