scipp / plopp

Visualization library for scipp
https://scipp.github.io/plopp/
BSD 3-Clause "New" or "Revised" License
7 stars 5 forks source link

Polar slicer plot not keeping xrange upon value change #374

Closed TheFermiSea closed 6 days ago

TheFermiSea commented 1 week ago

Hello,

I am trying to use a slicer plot to visualize my data in polar coordinates. It seems that pp.slicer is not setting the theta limits correctly. I have attempted to use p.canvas.xrange = 0., 2*np.pi, but this only sets the theta limits on initialization, which is reset once a slider is changed. I have attempted to inject an update node with no sucess. Here is a MWE:

'''

fig = plt.figure() ax = fig.add_subplot(projection='polar')

p = pp.slicer({'Data':_data, 'Fit':_fit}, keep=['theta'], marker={'Data':'o', 'Fit':''}, linestyle={'Data':'', 'Fit':'-'}, color={'Data':'k', 'Fit':'r'}, autoscale=True, legend=True, ax=ax ) p.canvas.xrange = 0., 2*np.pi p ''' image

and upon value change:

image

Please advise

nvaytet commented 1 week ago

Hi! Can I ask which version of plopp you have? Thanks

nvaytet commented 1 week ago

With the latest version (24.09.1), as long as I make sure I use autoscale=False, I can get a polar plot that does not mess up the axes. Example:

import numpy as np
import scipp as sc
import plopp as pp
import matplotlib.pyplot as plt
%matplotlib widget
plt.ioff()

# Make some spiral data
N = 150
r = sc.linspace('r', 0, 10, N, unit='m')
theta = sc.linspace('theta', 0, 12, N, unit='rad')
da = sc.DataArray(data=r * theta, coords={'theta': theta, 'r': r})

# Construct figure axes with Matplotlib
fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})

f = pp.slicer(da, ax=ax, grid=True, autoscale=False)
f.canvas.xrange = 0, 2 * np.pi
f.canvas.yrange = 0, 100
f

Screenshot at 2024-09-14 23-16-17

However, as soon as I hit the Home button in the toolbar, then the axes do get messed up like you report. I guess polar axes are not so well supported currently...