Log scale with 0 in pyqtgraph
Unsolved
General and Desktop
-
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_()
-
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-e3print(x) --> x = [1, 4, 0.001, 2, 3, 0.001, 1]
I hope this helps in some way.
Kind regards