Programmatically configuring plots¶
Plots in Glue are designed to be easily configured with Python. As much as possible, plot settings are controlled by simple properties on data viewer objects. For example:
from glue.core import Data, DataCollection
from glue.app.qt.application import GlueApplication
from glue.viewers.scatter.qt import ScatterWidget
import numpy as np
# create some data
d = Data(x=np.random.random(100), y=np.random.random(100))
dc = DataCollection([d])
# create a GUI session
ga = GlueApplication(dc)
# plot x vs y, flip the x axis, log-scale y axis
scatter = ga.new_data_viewer(ScatterWidget)
scatter.add_data(d)
scatter.xatt = d.id['x']
scatter.yatt = d.id['y']
scatter.xflip = True
scatter.ylog = True
# show the GUI
ga.start()
Plot Options¶
Here are the settings associated with each data viewer:
Scatter Plots
¶
xlog |
log scaling on x axis? |
ylog |
log scaling on y axis? |
xflip |
invert the x axis? |
yflip |
invert the y axis? |
xmin |
Lower x limit of plot |
xmax |
Upper x limit of plot |
ymin |
Lower y limit of plot |
ymax |
Upper y limit of plot |
hidden |
Show hidden attributes |
xatt |
Attribute to plot on x axis |
yatt |
Attribute to plot on y axis |
Image Viewer
¶
data |
Current data |
attribute |
Current attribute |
rgb_mode |
RGB Mode? |
slice |
Histogram Viewer
¶
xmin |
Minimum value |
xmax |
Maximum value |
normed |
Normalized? |
autoscale |
Autoscale view to histogram? |
cumulative |
Cumulative? |
nbins |
Number of bins |
xlog |
Log-scale the x axis? |
ylog |
Log-scale the y axis? |
Customizing Plots with Matplotlib¶
If you want, you can directly manipulate the Matplotlib plot objects that underly Glue plots. This can be useful if you want to create static plots with custom annotation, styles, etc.
From the GUI¶
Open the IPython terminal window. The application.viewers
variable
is a list of lists of all the
open plot windows. Each inner list contains the data viewers
open on a single tab. Every viewer has an axes
attribute,
which points to a Matplotlib Axes
object:
plot = application.viewers[0][0]
ax = plot.axes
ax.set_title('Custom title')
ax.figure.canvas.draw() # update the plot
From a script¶
Save the current glue session via File->Save Session
. You can
reload this session programmatically as follows:
from glue.app.qt.application import GlueApplication
app = GlueApplication.restore('output.glu', show=False)
plot = app.viewers[0][0]
ax = plot.axes