PlotPyStack / PythonQwt

Qt plotting widgets for Python (pure Python reimplementation of Qwt C++ library)
https://pypi.org/project/PythonQwt/
Other
86 stars 25 forks source link

Plot markers: labels and symbols are clipped #82

Closed luc-j-bourhis closed 7 months ago

luc-j-bourhis commented 7 months ago

Consider the code

from PyQt5 import QtWidgets, QtGui, QtCore
from PyQt5.QtCore import Qt
import qwt
import numpy as np

app = QtWidgets.QApplication([])
x = np.linspace(0, 4*np.pi, 100)
y = np.cos(x)
plot = qwt.QwtPlot("Sine function")
plot.enableAxis(plot.xBottom, False) #|Disable axes enabled by default
plot.enableAxis(plot.yLeft, False)   #|
plot.insertLegend(qwt.QwtLegend(), qwt.QwtPlot.BottomLegend)
qwt.QwtPlotCurve.make(x, y, "Sinus", plot, linecolor="blue", antialiased=True)
c = QtGui.QColor('purple')
sz = 10
s = qwt.QwtSymbol.make(
    style=qwt.QwtSymbol.Ellipse,
    brush=QtGui.QBrush(c), pen=QtGui.QPen(c),
    size=QtCore.QSize(sz, sz))
step = 5
for xi, yi in zip(x[::step], y[::step]):
    l = qwt.QwtText.make(text=f'{yi:0.2f}', pointsize=8)
    qwt.QwtPlotMarker.make(
        xvalue=xi, yvalue=yi,
        label=l,
        symbol=s,
        align=Qt.AlignTop,
        plot=plot)
plot.resize(1200, 600)
plot.show()
app.exec_()

and the attached outcomes: the green arrows drawn by hand shows where the circles used as markers and their associated text labels are clipped by the plot boundary. So it seems PythonQwt only make the curve fits but not the rest. I would consider that a bug but then is there a way to work around it? clipped

PierreRaybaut commented 7 months ago

Thanks for the feedback. Somehow I was waiting for this issue for quite some time, in a sense. The absence of margins in plots have been a recurring problem lately, for some applications.

I'll be back to you shortly.

For example, this is better I guess:

image

luc-j-bourhis commented 7 months ago

That plot would make me very happy!

On 15 Feb 2024, at 09:33, Pierre Raybaut @.***> wrote:

Thanks for the feedback. Somehow I was waiting for this issue for quite some time, in a sense. The absence of margins in plots have been a recurring problem lately, for some applications.

I'll be back to you shortly.

For example, this is better I guess:

image.png (view on web) https://github.com/PlotPyStack/PythonQwt/assets/1311787/40fe72b9-03e0-48c3-8c7a-38fee28e335e — Reply to this email directly, view it on GitHub https://github.com/PlotPyStack/PythonQwt/issues/82#issuecomment-1945592275, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACIC4NKFHDNJBAZAM5MZRLYTXB5HAVCNFSM6AAAAABDG4SIBCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBVGU4TEMRXGU. You are receiving this because you authored the thread.

PierreRaybaut commented 7 months ago

The previous screenshot will be the default result of the execution of your code, with PythonQwt 0.12 (default margins are 5% of the interval, at both ends of each axis).

Margins may also be adjusted like this:

# Increasing margins up to 10% at each end of the axes
plot.setAxisMargin(plot.yLeft, 0.1)
plot.setAxisMargin(plot.xBottom, 0.1)
luc-j-bourhis commented 7 months ago

I am testing it in my software: so far so good. Even with using setAxisScale with the minimum and maximum ordinate does not result in the labels or the markers being clipped. Thanks!

On 15 Feb 2024, at 13:50, Pierre Raybaut @.***> wrote:

The previous screenshot will be the default result of the execution of your code, with PythonQwt 0.12.

Margins may also be adjusted like this:

plot.setAxisMargin(plot.yLeft, 0.1) plot.setAxisMargin(plot.xBottom, 0.1) — Reply to this email directly, view it on GitHub https://github.com/PlotPyStack/PythonQwt/issues/82#issuecomment-1946037233, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACIC4KT2EPOUWWGH6IMEKLYTYABBAVCNFSM6AAAAABDG4SIBCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBWGAZTOMRTGM. You are receiving this because you authored the thread.

PierreRaybaut commented 7 months ago

You're very welcome.

By the way, if you're looking for more high-level features for visualizing curves and images, you may take a look at PlotPy which is based on PythonQwt.

luc-j-bourhis commented 7 months ago

Thanks for the pointer: from a quick look at the documentation, it looks like PlotPy supports panning and dragging out of the box. Does it? Does PythonQwt support those features too? The use case I have in mind in the user clicking on the graph, and dragging to pan a graph that is larger than the window displaying it.

On 16 Feb 2024, at 14:36, Pierre Raybaut @.***> wrote:

You're very welcome.

By the way, if you're looking for more high-level features for visualizing curves and images, you may take a look at PlotPy https://github.com/PlotPyStack/plotpy which is based on PythonQwt.

— Reply to this email directly, view it on GitHub https://github.com/PlotPyStack/PythonQwt/issues/82#issuecomment-1948397765, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACIC4MG3DUX5PKNI53C4KTYT5OEBAVCNFSM6AAAAABDG4SIBCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBYGM4TONZWGU. You are receiving this because you authored the thread.

PierreRaybaut commented 7 months ago

Exactly, zoom/pan features are not implemented in PythonQwt but are available in PlotPy.

luc-j-bourhis commented 7 months ago

I will seriously look into PlotPy then! Thanks again!

On 16 Feb 2024, at 15:21, Pierre Raybaut @.***> wrote:

Exactly, zoom/pan features are not implemented in PythonQwt but are available in PlotPy.

— Reply to this email directly, view it on GitHub https://github.com/PlotPyStack/PythonQwt/issues/82#issuecomment-1948470573, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACIC4L2MMPZRAJPXDS5MRDYT5TN7AVCNFSM6AAAAABDG4SIBCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBYGQ3TANJXGM. You are receiving this because you authored the thread.