Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize plot appearance and export scripts #1511

Merged
merged 32 commits into from
Feb 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c9491eb
Make sure that plugin package imports failing does not crash glue
astrofrog Jan 30, 2018
c1da6b1
Added the ability to set some of the visual properties of Matplotlib …
astrofrog Jan 30, 2018
4c94556
Added GUI controls for Matplotlib axes appearance
astrofrog Jan 30, 2018
84fb051
Started adding functionality to export scripts
astrofrog Jan 31, 2018
a98d63c
Make exporting of plots possible from GUI
astrofrog Jan 31, 2018
ad7959f
Added tests of Python export, and fix bugs
astrofrog Jan 31, 2018
ea0964d
Test more Python export functionality
astrofrog Jan 31, 2018
47198fd
Fix for NaN sizes
astrofrog Jan 31, 2018
eb9fcce
Simplifications to Python export
astrofrog Feb 1, 2018
07a9f9b
Simplify generated code, especially for colors
astrofrog Feb 6, 2018
f05d7ca
Improve formatting of output scripts
astrofrog Feb 6, 2018
1cfc48d
Remove unused line
astrofrog Feb 6, 2018
e2a1385
Test subset plotting
astrofrog Feb 6, 2018
4405863
Implemented exporting for histogram
astrofrog Feb 6, 2018
5aafa42
Fix case where histogram is empty
astrofrog Feb 6, 2018
523a64e
Starting adding plot export functionality for image viewer
astrofrog Feb 6, 2018
7e7708b
Added another test for the image Python export
astrofrog Feb 6, 2018
4bcd805
Don't open session file in bytes mode
astrofrog Feb 6, 2018
2043328
Refactor to include all Python export code in dedicated files
astrofrog Feb 6, 2018
0d389d3
Close figure explicitly
astrofrog Feb 6, 2018
2ba87f6
Be smart about setting the histogram limits to be explicitly the min/…
astrofrog Feb 7, 2018
6090320
Update minimum required version of Matplotlib
astrofrog Feb 7, 2018
c2c52f5
Produce more useful debugging information when the Python export test…
astrofrog Feb 14, 2018
8cbd327
Factor out common code from Python export tests
astrofrog Feb 14, 2018
0010628
Fix compatibility with Matplotlib 1.5
astrofrog Feb 15, 2018
0195fad
Fix all tests except one which is xfailed with Matplotlib 1.5
astrofrog Feb 15, 2018
aa574bc
Travis: Don't install awscli
astrofrog Feb 16, 2018
c5b7342
Implement saving of density map in scatter plot
astrofrog Feb 16, 2018
1ad9b29
Rename myplot.png to glue_plot.png
astrofrog Feb 16, 2018
8348a57
Use NumpyRNGContext to avoid statistical flukes on CI
astrofrog Feb 16, 2018
3f5e106
Add a margin by default to the limits determined in the scatter plot …
astrofrog Feb 16, 2018
4f8ac63
Travis: change Matplotlib version back to 1.5
astrofrog Feb 16, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env:
- QT_PKG=pyqt5
- SETUP_XVFB=True
- CONDA_DEPENDENCIES="pip dill ipython matplotlib scipy cython h5py pygments pyzmq scikit-image pandas sphinx xlrd pillow pytest mock coverage pyyaml sphinx_rtd_theme qtpy traitlets ipykernel qtconsole spectral-cube pytest-cov mpl-scatter-density"
- PIP_DEPENDENCIES="coveralls pyavm astrodendro awscli plotly objgraph"
- PIP_DEPENDENCIES="coveralls pyavm astrodendro plotly objgraph"
- PIP_FALLBACK=false
- REMOVE_INSTALL_REQUIRES=0
- secure: NvQVc3XmmjXNVKrmaD31IgltsOImlnt3frAl4wU0pM223iejr7V57hz/V5Isx6sTANWEiRBMG27v2T8e5IiB7DQTxFUleZk3DWXQV1grw/GarEGUawXAgwDWpF0AE/7BRVJYqo2Elgaqf28+Jkun8ewvfPCiEROD2jWEpnZj+IQ=
Expand Down Expand Up @@ -116,7 +116,7 @@ matrix:

- os: linux
env: PYTHON_VERSION=2.7 NUMPY_VERSION=dev
PIP_DEPENDENCIES="pytest-cov coveralls pyavm astrodendro awscli plotly"
PIP_DEPENDENCIES="pytest-cov coveralls pyavm astrodendro plotly"

- os: linux
env: PYTHON_VERSION=2.7 QT_PKG=pyside
Expand Down
2 changes: 1 addition & 1 deletion doc/installation/dependencies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Glue has the following required dependencies:

* Python 2.7, or 3.3 and higher
* `Numpy <http://www.numpy.org>`_ 1.9 or later
* `Matplotlib <http://matplotlib.org/>`_ 1.4 or later
* `Matplotlib <http://matplotlib.org/>`_ 2.0 or later
* `Pandas <http://pandas.pydata.org/>`_ 0.14 or later
* `Astropy <http://www.astropy.org>`_ 1.0 or higher
* `setuptools <http://setuptools.readthedocs.io/en/latest/>`_ 1.0 or later
Expand Down
12 changes: 12 additions & 0 deletions glue/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,18 @@ def add(self, label, cmap):
"""
self.members.append([label, cmap])

def __getitem__(self, cmap_name):
for name, cmap in self.members:
if name == cmap_name:
return cmap
raise KeyError(cmap_name)

def name_from_cmap(self, cmap_desired):
for name, cmap in self.members:
if cmap is cmap_desired:
return name
raise ValueError("Could not find name for colormap")


class DataFactoryRegistry(Registry):

Expand Down
3 changes: 3 additions & 0 deletions glue/core/data_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ def __iter__(self):
def __len__(self):
return len(self._data)

def index(self, item):
return self._data.index(item)

def __str__(self):
if len(self) == 1:
result = "DataCollection (1 data set)\n\t"
Expand Down
12 changes: 12 additions & 0 deletions glue/core/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ def load(rec, context)
PATH_PATCHES[before.strip()] = after.strip()


def save(filename, obj):
s = GlueSerializer(obj)
with open(filename, 'w') as f:
s.dump(f)


def load(filename):
with open(filename, 'r') as f:
s = GlueUnSerializer.load(f)
return s.object('__main__')


def lookup_class_with_patches(name):
"""
A wrapper to lookup_class that also patches paths to ensure
Expand Down
16 changes: 15 additions & 1 deletion glue/core/state_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ class StateAttributeLimitsHelper(StateAttributeCacheHelper):
percentile_subset : int
How many points to use at most for the percentile calculation (using all
values is highly inefficient and not needed)
margin : float
Whether to add a margin to the range of values determined. This should be
given as a floating point value that will be multiplied by the range of
values to give the margin to add to the limits.
lower, upper : str
The fields for the lower/upper levels
percentile : ``QComboBox`` instance, optional
Expand All @@ -279,10 +283,11 @@ class StateAttributeLimitsHelper(StateAttributeCacheHelper):
values_names = ('lower', 'upper')
modifiers_names = ('log', 'percentile')

def __init__(self, state, attribute, percentile_subset=10000, cache=None, **kwargs):
def __init__(self, state, attribute, percentile_subset=10000, margin=0, cache=None, **kwargs):

super(StateAttributeLimitsHelper, self).__init__(state, attribute, cache=cache, **kwargs)

self.margin = margin
self.percentile_subset = percentile_subset

if self.attribute is not None:
Expand Down Expand Up @@ -352,6 +357,15 @@ def update_values(self, force=False, use_default_modifiers=False, **properties):
lower = np.floor(lower - 0.5) + 0.5
upper = np.ceil(upper + 0.5) - 0.5

if log:
value_range = np.log10(upper / lower)
lower /= 10.**(value_range * self.margin)
upper *= 10.**(value_range * self.margin)
else:
value_range = upper - lower
lower -= value_range * self.margin
upper += value_range * self.margin

self.set(lower=lower, upper=upper, percentile=percentile, log=log)

def flip_limits(self):
Expand Down
Binary file added glue/icons/glue_pythonsave.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading