logo
Tags down

shadow

Zoom only in x or y direction in pyqtgraph using mouse


By : Jesus Carrillo
Date : October 15 2020, 06:10 PM
Does that help You can use setMouseEnabled(). From the documentation:
code :
setMouseEnabled(x=None, y=None)
import pyqtgraph as pg

plot_widget = pg.PlotWidget() 
plot_widget.plotItem.setMouseEnabled(y=False) # Only allow zoom in X-axis
plot_widget.plotItem.setMouseEnabled(x=False) # Only allow zoom in Y-axis


Share : facebook icon twitter icon

Zoom in and out a ViewBox with mouse scroll and use mouse pointer location as zoom origin


By : ismo
Date : March 29 2020, 07:55 AM
To fix this issue better way is to use the RenderTransform property (particularly ScaleTransform in your case). Have a read here
this could be useful: Pan & Zoom Image

Edges with Direction in pyqtgraph GraphItem


By : Ankit Mathur
Date : March 29 2020, 07:55 AM
wish of those help For direction, you might add a pg.ArrowItem at the end of each line (although this could have poor performance for large networks), and for self connections, QtGui.QGraphicsEllipseItem combined with an arrow.

Unity 2D Mouse Zoom, but zoom in to location of mouse point


By : Sylvain from yoorock
Date : March 29 2020, 07:55 AM
wish helps you Edit : I need an answer for a 2D implementation, not 3D. So the 'Asked Before' question doesn't work for my project. , I haven't tried this myself but I hope this will work.
code :
Vector3 newPosition;
bool canZoom;
bool isMoving;

void Update () 
{
    if (Input.GetAxis("Mouse ScrollWheel") > 0 && zoom > 9)
    {
        zoom -= 1;
        canZoom = true;
    }

    if (Input.GetAxis("Mouse ScrollWheel") < 0 && zoom < 101)
    {
        zoom += 1;
        canZoom = true;
    }

     if (canZoom) 
     {
        isMoving = true;
        Camera.main.orthographicSize = zoom;
        newPosition = Camera.main.ScreenToWorldPoint (Input.mousePosition);
     }
     if (isMoving)
     {
        transform.position = Vector3.Lerp (transform.position,  newPosition, Time.deltaTime);
     }

     if(transform.position == newPosition)
     {
         isMoving = false;
     }

}

Graphics in PyQtGraph not updating after zoom


By : derMahler
Date : March 29 2020, 07:55 AM
will help you You should not update the painting if you want to change position, you should only use setPos(). the paint() function takes boundingRect() as a reference so when moving the graph you are moving it in that coordinate system instead of the coordinate system of PlotWidget.
code :
class SquareItem(GraphicsObject):
    def paint(self, p, *args):
        p.setBrush(mkBrush('r'))
        p.setPen(mkPen(None))
        p.drawRect(self.boundingRect())

    def boundingRect(self):
        return QtCore.QRectF(0, 0, 1, 1)

    def update_position(self, x):
        self.setPos(x, 0)


class MainWindow(QtWidgets.QMainWindow):
    def __init__(self, parent=None):
        super().__init__(parent)

        self.setWindowTitle('Micromouse maze simulator')
        self.resize(600, 600)

        frame = QtWidgets.QFrame()
        layout = QtWidgets.QVBoxLayout(frame)

        self.graphics = PlotWidget()
        self.graphics.setAspectLocked()
        self.item = SquareItem()
        self.graphics.addItem(self.item)

        self.graphics.setRange(rect=QtCore.QRectF(-10, -10, 20, 20))

        self.slider = QSlider(QtCore.Qt.Horizontal)
        self.slider.setSingleStep(1)
        self.slider.setPageStep(10)
        self.slider.setRange(0, 10)
        self.slider.setTickPosition(QSlider.TicksAbove)
        self.slider.valueChanged.connect(self.slider_value_changed)
        self.slider.setValue(1)

        layout.addWidget(self.graphics)
        layout.addWidget(self.slider)

        self.setCentralWidget(frame)

    def slider_value_changed(self, value):
        self.item.update_position(value)
import sys

from PyQt5 import QtCore, QtWidgets
from pyqtgraph import (
    mkBrush,
    mkPen,
    GraphicsObject,
    QtGui,
    PlotWidget,
)

class MainWindow(QtWidgets.QMainWindow):
    def __init__(self, parent=None):
        super().__init__(parent)

        self.setWindowTitle('Micromouse maze simulator')
        self.resize(600, 600)

        frame = QtWidgets.QFrame()
        layout = QtWidgets.QVBoxLayout(frame)

        self.graphics = PlotWidget()
        self.graphics.setAspectLocked()
        self.item = QtWidgets.QGraphicsRectItem(0, 0, 1, 1)
        self.item.setBrush(mkBrush('r'))
        self.item.setPen(mkPen(None))
        self.graphics.addItem(self.item)

        self.graphics.setRange(rect=QtCore.QRectF(-10, -10, 20, 20))

        self.slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
        self.slider.setSingleStep(1)
        self.slider.setPageStep(10)
        self.slider.setRange(0, 10)
        self.slider.setTickPosition(QtWidgets.QSlider.TicksAbove)
        self.slider.valueChanged.connect(self.slider_value_changed)
        self.slider.setValue(1)

        layout.addWidget(self.graphics)
        layout.addWidget(self.slider)

        self.setCentralWidget(frame)

    def slider_value_changed(self, value):
        self.item.setPos(value, 0)


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    main = MainWindow()
    main.show()
    sys.exit(app.exec_())
import sys

from PyQt5 import QtCore, QtWidgets

from pyqtgraph import (
    mkBrush,
    mkPen,
    GraphicsObject,
    QtGui,
    PlotWidget,
)


class SquareItem(GraphicsObject):
    colors = ['r', 'g', 'b', 'c', 'm', 'y', 'k', 'w', 'FF0', 'AA0', '0AA']
    def __init__(self):
        super().__init__()
        self.mColor = SquareItem.colors[0]

    def paint(self, p, *args):
        p.setBrush(mkBrush(self.mColor))
        p.setPen(mkPen(None))
        p.drawRect(self.boundingRect())

    def boundingRect(self):
        return QtCore.QRectF(0, 0, 1, 1)

    def update_draw(self, x):
        self.mColor = SquareItem.colors[x]
        self.update()


class MainWindow(QtWidgets.QMainWindow):
    def __init__(self, parent=None):
        super().__init__(parent)

        self.setWindowTitle('Micromouse maze simulator')
        self.resize(600, 600)

        frame = QtWidgets.QFrame()
        layout = QtWidgets.QVBoxLayout(frame)

        self.graphics = PlotWidget()
        self.graphics.setAspectLocked()
        self.item = SquareItem()
        self.graphics.addItem(self.item)

        self.graphics.setRange(rect=QtCore.QRectF(-10, -10, 20, 20))

        self.slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
        self.slider.setSingleStep(1)
        self.slider.setPageStep(10)
        self.slider.setRange(0, 10)
        self.slider.setTickPosition(QtWidgets.QSlider.TicksAbove)
        self.slider.valueChanged.connect(self.item.update_draw)
        self.slider.setValue(1)

        layout.addWidget(self.graphics)
        layout.addWidget(self.slider)

        self.setCentralWidget(frame)

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    main = MainWindow()
    main.show()
    sys.exit(app.exec_())

Image in pyqtgraph is hidden due to zoom


By : user2707894
Date : March 29 2020, 07:55 AM
will help you I was answered on the support forum and it works for me. question on forum
It seems to be a rounding error. Need replace method of boundingRect.
code :
    # import numpy as np
    def boundingRect(self):
        data = np.array(self.data)
        xmin = data[:,0].min()
        xmax = data[:,0].max()
        ymin = data[:,1:].min()
        ymax = data[:,1:].max()
        return QtCore.QRectF(xmin, ymin, xmax-xmin, ymax-ymin)
Related Posts Related Posts :
  • Python hex string encoding
  • Get week start date from week number
  • How to use imports from requirements.txt in python
  • Removing tab indent in ipython shell
  • I need to remove duplicates from a list but add the numeric value in them
  • Delay default arguments being read until function is called
  • Interpolate / fillna with a decay formula in pandas
  • What python package can translate Greek letter to ASCII requivalent?
  • How to get output of OS command from Jupyter notebook?
  • Printing AND writing the RIGHTLY formatted number
  • How do I create a shortcut to import most used python modules?
  • Matplotlib: Show selected date labels on x axis
  • Understanding memoization in Python
  • why does the len function return 2 on some iterations when they are all the same length?
  • Change in preference value does not affect the results of Affinity propagation Clustering
  • returning values inside a function
  • Why cant I use a variable in str slicing?
  • Section divider in Spyder
  • Conditional statement in selenium if element does not exists
  • Pandas : how to select index/row label in dataframe that matches a condition
  • What does zero do in A[0] in this code? Why not empty or another number?
  • Google App Engine urlfetch PayloadTooLargeError: Request exceeds 10 MiB limit for URL
  • Is there a way to set up optional arguments to bypass input arguments?
  • Suppress OpenMP debug messages when running Tensorflow on CPU
  • How to do GridSearchCV for F1-score in classification problem with scikit-learn?
  • Why does .pop() eventually stop and not keep removing items from a list until the list is empty?
  • How do I acess my Spider data from my main.py script?
  • Python Pandas Expand a Column of List of Lists to Two New Column
  • Overhead of python multiprocessing initialization is worse than benefits
  • Python Joining List and adding and removing characters
  • Adding an lxml library to project
  • Concatenating tensors in Tensorflow with None axis
  • Need help understanding why i get attribute error
  • How to force a MIDI device to report control status?
  • What does *** mean in Python -3?
  • How to get GFCC instead of MFCC in python?
  • How do I print a number n times in python?
  • How do i split a string wherever there are digits?
  • List Comprehension Python Prime numbers
  • "list index out of range" when reading data from file
  • What's the correct datetime format for the specified date string?
  • I cannot import CSV file?
  • Matplotlib pyplot plots look different after calling pandas profiling. How can I fix this?
  • Stopping all the instances of a specific region
  • Deal with Birtish summer time
  • Unable to use ColorWheel without loading kv (AttributeError)
  • What are these characters called: 。. !?etc Trying to split sentences stops working with non standard characters
  • rand.randint returning same number over and over?
  • Find longest sequence that does not contain a certain number
  • How do I convert a map object to list and also assign to a variable
  • sympy error: 'Symbol' object has no attribute 'pi'
  • How to remove words without vowels from a list in python
  • Downloading python to macbook
  • TypeError: __init__() missing 1 required positional argument: 'units'
  • Check if a class is a dataclass in Python
  • Unable to scrape google news heading via their class
  • Array of structs with dynamic allocation runs very slow in C in comparison to Python
  • Python Pandas - find all unique combinations of rows of a DataFrame without repeating values in the columns
  • How do I change the numbers in a cell to the word 'Bus' in Pandas Python
  • 'ascii' codec can't encode character : ordinal not in range (128)
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk