Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Log scale with 0 in pyqtgraph
Forum Updated to NodeBB v4.3 + New Features

Log scale with 0 in pyqtgraph

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 458 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qt_is_not_easy
    wrote on last edited by
    #1

    I am baffled by implementing a symlog (matplotlib equivalent for symmetric log scale) in pyqtgraph. I wonder if I can make a broken axis plot in pyqtgraph. I am attaching a sample code of a plot for reference, but I don't think that would be helpful.

    Thanks in advance

    import pyqtgraph as pg
    from PyQt5.QtWidgets import QApplication
    from pyqtgraph.Qt import QtGui
    from pyqtgraph.widgets.RemoteGraphicsView import RemoteGraphicsView
    # Create a PyQtGraph application instance
    app = QApplication([])
    
    # Create two PlotItems and link their X-axis
    plot_item1 = pg.PlotItem()
    plot_item2 = pg.PlotItem()
    plot_item1.setXLink(plot_item2)
    
    # Create some example data
    x1 = [1, 2, 3, 4, 5]
    x2 = [1.1, 2.1, 3.1, 4.4, 5.2]
    y1 = [1, 2, 3, 2, 1]
    y2 = [1, 4, 2, 3, 1]
    
    # Plot the data on each PlotItem
    plot_item1.plot(x1, y1)
    plot_item2.plot(x2, y2)
    
    # Create a layout and add the PlotItems to it
    layout = pg.GraphicsLayout()
    layout.addItem(plot_item1, 0, 0)
    layout.addItem(plot_item2, 1, 1)
    # layout.resize(500,300)
    
    # Show the plot
    # view = pg.GraphicsView()
    # l = pg.GraphicsLayout()
    win = pg.GraphicsView()
    win.setCentralItem(layout)
    win.show()
    
    # Start the event loop
    app.exec_()
    
    
    1 Reply Last reply
    0
    • T Offline
      T Offline
      thelegend27
      wrote on last edited by thelegend27
      #2

      I stumbled over the same problem and I haven't found a "symlog" for pyqtgraph yet...

      Since the log value for zero can not be defined, whilst small values close to zero are defined, the zero values can be set to a value close to zero (e.g. 1e-3, or maybe even lower... e.g. 1e-10).

      x = [1, 4, 0, 2, 3, 0, 1]
      x[x==0] = 1-e3

      print(x) --> x = [1, 4, 0.001, 2, 3, 0.001, 1]

      I hope this helps in some way.
      Kind regards

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved