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

Colorbar under histogram #2514

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import numpy as np

import bqplot
import numpy as np
from astropy.visualization import (
ManualInterval, ContrastBiasStretch, PercentileInterval
)
Expand Down Expand Up @@ -639,6 +640,12 @@ def _update_stretch_histogram(self, msg={}):
sub_data = sub_data[~np.isnan(sub_data)]

self.stretch_histogram._update_data('histogram', x=sub_data)
self.stretch_histogram.figure.axes[2] = bqplot.ColorAxis(scale=bqplot.ColorScale(
scheme="Greys", #self.image_colormap_value, # FIXME: How to map from glue to Colorbrewer?
reverse=True,
scale_type=self.stretch_function_value, # FIXME: bqscales only knows "linear"
min=self.stretch_vmin_value,
max=self.stretch_vmax_value))

if len(sub_data) > 0:
interval = PercentileInterval(95)
Expand Down
27 changes: 14 additions & 13 deletions jdaviz/core/template_mixin.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
from astropy.coordinates.sky_coordinate import SkyCoord
from astropy.nddata import NDData
from astropy.table import QTable
from astropy.table.row import Row as QTableRow
import astropy.units as u
import bqplot
from contextlib import contextmanager
import numpy as np
import os
import threading
import time
from contextlib import contextmanager
from functools import cached_property

import bqplot
import numpy as np
from astropy import units as u
from astropy.coordinates.sky_coordinate import SkyCoord
from astropy.nddata import NDData
from astropy.table import QTable
from astropy.table.row import Row as QTableRow
from echo import delay_callback
from functools import cached_property
from ipypopout import PopoutButton
from ipyvuetify import VuetifyTemplate
from ipywidgets import widget_serialization
from glue.config import colormaps
from glue.core import Data, HubListener
from glue.core.link_helpers import LinkSame
Expand All @@ -30,9 +32,6 @@
from specutils import Spectrum1D
from traitlets import Any, Bool, HasTraits, List, Unicode, observe

from ipywidgets import widget_serialization
from ipypopout import PopoutButton

from jdaviz import __version__
from jdaviz.components.toolbar_nested import NestedJupyterToolbar
from jdaviz.core.events import (AddDataMessage, RemoveDataMessage,
Expand Down Expand Up @@ -3284,13 +3283,15 @@ def __init__(self, plugin, viewer_type='scatter', app=None, *args, **kwargs):
self._viewer_type = viewer_type
if viewer_type == 'histogram':
self._viewer_components = ('x',)
axis_c = bqplot.ColorAxis(scale=bqplot.ColorScale())
self.viewer.figure.axes.append(axis_c)
else:
self._viewer_components = ('x', 'y')
self.figure = self.viewer.figure
self._marks = {}

self.figure.title_style = {'font-size': '12px'}
self.figure.fig_margin = {'top': 60, 'bottom': 60, 'left': 60, 'right': 10}
self.figure.fig_margin = {'top': 60, 'bottom': 100, 'left': 60, 'right': 10}

self.toolbar = NestedJupyterToolbar(self.viewer, self.tools_nested, [])

Expand Down
149 changes: 149 additions & 0 deletions notebooks/concepts/imviz_colorbar_mpl.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "7b9bf568-7416-46ad-9108-0d1d97c9af32",
"metadata": {},
"source": [
"Concept notebook to explore colorbar implementation in bqplot vs Matplotlib.\n",
"\n",
"Matplotlib example is from https://docs.astropy.org/en/latest/visualization/normalization.html ."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9c6f2384-b70b-4106-973d-b62623d67e5f",
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from astropy.visualization import simple_norm\n",
"\n",
"# Generate a test image\n",
"image = np.arange(65536).reshape((256, 256))\n",
"\n",
"# Create an ImageNormalize object\n",
"norm = simple_norm(image, 'sqrt')\n",
"\n",
"# Display the image\n",
"fig = plt.figure()\n",
"ax = fig.add_subplot(1, 1, 1)\n",
"im = ax.imshow(image, origin='lower', norm=norm)\n",
"fig.colorbar(im)"
]
},
{
"cell_type": "markdown",
"id": "5ab7bbf6-372b-4aa0-9f02-a5dacace164e",
"metadata": {},
"source": [
"How, how does Imviz fare?"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3b04c9b4-ddf4-4025-aea2-77d5920e53dd",
"metadata": {},
"outputs": [],
"source": [
"from jdaviz import Imviz"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e9349094-620b-40c4-8ae2-d424b5983119",
"metadata": {},
"outputs": [],
"source": [
"imviz = Imviz()\n",
"imviz.load_data(image, data_label=\"test image\")\n",
"imviz.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "83167260-2cc8-4e33-9fd0-9105db23d521",
"metadata": {},
"outputs": [],
"source": [
"imviz.default_viewer.zoom_level = \"fit\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "27a06c70-b7af-4055-9b50-2d1269ba38d3",
"metadata": {},
"outputs": [],
"source": [
"plg = imviz.plugins[\"Plot Options\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ed2c2107-1803-4481-81b9-e6ab162e7425",
"metadata": {},
"outputs": [],
"source": [
"plg.image_colormap = \"Viridis\"\n",
"plg.stretch_function = \"Square Root\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3ca8ca87-c8aa-4ff3-b4d8-b4c07e22db90",
"metadata": {},
"outputs": [],
"source": [
"import bqplot\n",
"\n",
"plg._obj.stretch_histogram.figure.axes[2].scale = bqplot.ColorScale(\n",
" scheme=\"YlGnBu\", #self.image_colormap_value, # FIXME: How to map from glue to Colorbrewer?\n",
" reverse=True,\n",
" scale_type=\"linear\", #plg._obj.stretch_function_value, # FIXME: bqscales only knows \"linear\"\n",
" min=plg._obj.stretch_vmin_value,\n",
" max=plg._obj.stretch_vmax_value)\n",
"\n",
"# FIXME: Have to pop out the histogram to see the colorbar."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2ef6b087-04af-4f91-8bc5-bd0c50f2601a",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}