Skip to content

Commit

Permalink
Merge pull request #317 from adonath/astropy_style_docs_plots
Browse files Browse the repository at this point in the history
Using consistent plotting style in docs
  • Loading branch information
cdeil committed Aug 5, 2015
2 parents 28b9048 + 5d6823c commit 0c96597
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 37 deletions.
5 changes: 2 additions & 3 deletions docs/astro/population/plot_radial_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@

max_radius = 20 # kpc
r = np.linspace(0, max_radius, 100)
colors = ['b', 'k', 'k', 'b', 'g', 'g']

for color, key in zip(colors, radial_distributions):
for key in radial_distributions:
model = radial_distributions[key]()
if model.evolved:
linestyle = '-'
else:
linestyle = '--'
label = model.__class__.__name__
plt.plot(r, normalize(model, 0, max_radius)(r), color=color, linestyle=linestyle, label=label)
plt.plot(r, normalize(model, 0, max_radius)(r), linestyle=linestyle, label=label)
plt.xlim(0, max_radius)
plt.ylim(0, 0.28)
plt.xlabel('Galactocentric Distance [kpc]')
Expand Down
5 changes: 2 additions & 3 deletions docs/astro/population/plot_velocity_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@

v_min, v_max = 10, 3000 # km / s
v = np.linspace(v_min, v_max, 200)
colors = ['b', 'k', 'g']

for color, key in zip(colors, velocity_distributions):
for key in velocity_distributions:
model = velocity_distributions[key]()
label = model.__class__.__name__
plt.plot(v, normalize(model, v_min, v_max)(v), color=color, linestyle='-', label=label)
plt.plot(v, normalize(model, v_min, v_max)(v), linestyle='-', label=label)

plt.xlim(v_min, v_max)
plt.ylim(0, 0.004)
Expand Down
2 changes: 1 addition & 1 deletion docs/astro/source/plot_pulsar_spindown.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

t = Quantity(np.logspace(0, 6, 100), 'yr')
pulsar = Pulsar(P_0=Quantity(0.01, 's'), logB=12)
plt.plot(t.value, 1 / pulsar.period(t).cgs.value, color='b')
plt.plot(t.value, 1 / pulsar.period(t).cgs.value)
plt.xlabel('time [years]')
plt.ylabel('frequency [1/s]')
plt.ylim(1E0, 1E2)
Expand Down
9 changes: 4 additions & 5 deletions docs/astro/source/plot_snr_brightness_evolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
from gammapy.astro.source import SNR

densities = Quantity([1, 0.1], 'cm^-3')
colors = ['b', 'g']

t = Quantity(np.logspace(0, 5, 100), 'yr')

for color, density in zip(colors, densities):
for density in densities:
snr = SNR(n_ISM=density)
F = snr.luminosity_tev(t) / (4 * np.pi * Quantity(1, 'kpc') ** 2)
plt.plot(t.value, F.to('ph s^-1 cm^-2').value, color=color, label='n_ISM = {0}'.format(density.value))
plt.vlines(snr.sedov_taylor_begin.to('yr').value, 1E-13, 1E-10, linestyle='--', color=color)
plt.vlines(snr.sedov_taylor_end.to('yr').value, 1E-13, 1E-10, linestyle='--', color=color)
plt.plot(t.value, F.to('ph s^-1 cm^-2').value, label='n_ISM = {0}'.format(density.value))
plt.vlines(snr.sedov_taylor_begin.to('yr').value, 1E-13, 1E-10, linestyle='--')
plt.vlines(snr.sedov_taylor_end.to('yr').value, 1E-13, 1E-10, linestyle='--')
plt.xlim(1E2, 1E5)
plt.ylim(1E-13, 1E-10)
plt.xlabel('time [years]')
Expand Down
5 changes: 2 additions & 3 deletions docs/astro/source/plot_snr_radius_evolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
snr_models = [SNR, SNRTrueloveMcKee]
densities = Quantity([1, 0.1], 'cm^-3')
linestyles = ['-', '--']
colors = ['b', 'g']
t = Quantity(np.logspace(0, 5, 100), 'yr')

for color, density in zip(colors, densities):
for density in densities:
for linestyle, snr_model in zip(linestyles, snr_models):
snr = snr_model(n_ISM=density)
plt.plot(t.value, snr.radius(t).to('pc').value,
label=snr.__class__.__name__ + ' (n_ISM = {0})'.format(density.value),
linestyle=linestyle, color=color)
linestyle=linestyle)
plt.xlabel('time [years]')
plt.ylabel('radius [pc]')
plt.legend(loc=4)
Expand Down
8 changes: 5 additions & 3 deletions docs/background/plot_bgcube.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@
bg_model = CubeBackgroundModel.read(filename, format='table')

fig, axes = plt.subplots(nrows=1, ncols=3)
fig.set_size_inches(30., 8., forward=True)
fig.set_size_inches(20, 6., forward=True)

# plot images
bg_model.plot_image(energy=Quantity(0.5, 'TeV'), ax=axes[0], style_kwargs=dict(norm=LogNorm()))
bg_model.plot_image(energy=Quantity(50., 'TeV'), ax=axes[1], style_kwargs=dict(norm=LogNorm()))

# plot spectra
bg_model.plot_spectrum(det=Angle([0., 0.], 'degree'), ax=axes[2],
style_kwargs=dict(color='blue', label='(0, 0) deg'))
style_kwargs=dict(label='(0, 0) deg'))
bg_model.plot_spectrum(det=Angle([2., 2.], 'degree'), ax=axes[2],
style_kwargs=dict(color='red', label='(2, 2) deg'))
style_kwargs=dict(label='(2, 2) deg'))
axes[2].set_title('')
axes[2].legend()
axes[2].set_aspect(0.4)

plt.tight_layout()
plt.show()
6 changes: 6 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
from astropy_helpers.sphinx.conf import *
from astropy.extern import six

# Use the gamapy style when building docs
from gammapy.utils.mpl_style import gammapy_mpl_style

plot_rcparams = gammapy_mpl_style
plot_apply_rcparams = True

# Get configuration information from setup.cfg
from distutils import config
conf = config.ConfigParser()
Expand Down
6 changes: 3 additions & 3 deletions docs/image/colormap_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# Plot with the HESS and Milagro colormap
vmin, vmax, vtransition = -5, 15, 5
plt.figure(figsize=(8, 4))
plt.figure(figsize=(12, 6))

normalize = ImageNormalize(vmin=vmin, vmax=vmax, stretch=LinearStretch())
transition = normalize(vtransition)
Expand All @@ -26,14 +26,14 @@
cmap = colormap_hess(transition=transition)
plt.imshow(image, cmap=cmap, norm=normalize)
plt.axis('off')
plt.colorbar()
plt.colorbar(shrink=0.7)
plt.title('HESS-style colormap')

plt.subplot(122)
cmap = colormap_milagro(transition=transition)
plt.imshow(image, cmap=cmap, norm=normalize)
plt.axis('off')
plt.colorbar()
plt.colorbar(shrink=0.7)
plt.title('MILAGRO-style colormap')

plt.show()
2 changes: 2 additions & 0 deletions docs/irf/plot_fermi_psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
filename = FermiGalacticCenter.filenames()['psf']
fermi_psf = EnergyDependentTablePSF.read(filename)

plt.figure(figsize=(6, 6))

energies = Quantity([1], 'GeV')
for energy in energies:
psf = fermi_psf.table_psf_at_energy(energy=energy)
Expand Down
3 changes: 2 additions & 1 deletion docs/tutorials/background/source_diffuse_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
n_iterations = 4

# *** RUN & PLOT ***
plt.figure(figsize=(8, 4))

for iteration in range(n_iterations):
ibe.run_iteration()
Expand All @@ -71,4 +72,4 @@
plt.title('Significance Image, Iteration {0}'.format(iteration),
fontsize='small')

plt.tight_layout()
plt.subplots_adjust(wspace=0.05, hspace=0.05, left=0.05, right=0.95)
2 changes: 1 addition & 1 deletion gammapy/background/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ def plot_image(self, energy, ax=None, style_kwargs=None):
#import IPython; IPython.embed()

if not 'cmap' in style_kwargs:
style_kwargs['cmap'] = 'afmhot'
style_kwargs['cmap'] = 'gist_heat'

image = ax.imshow(data.value,
extent=extent.value,
Expand Down
8 changes: 4 additions & 4 deletions gammapy/image/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ def illustrate_colormap(cmap, **kwargs):
import matplotlib.pyplot as plt
cmap = plt.cm.get_cmap(cmap)
cmap_gray = grayify_colormap(cmap, **kwargs)
figure = plt.figure(figsize=(6, 4))
figure = plt.figure(figsize=(8, 6))
v = np.linspace(0, 1, 4 * cmap.N)

# Show colormap
Expand All @@ -673,9 +673,9 @@ def illustrate_colormap(cmap, **kwargs):

# Plot RGB profiles
plot_rgb = figure.add_axes([0.1, 0.1, 0.8, 0.6])
plot_rgb.plot(v, [cmap(_)[0] for _ in v], color='r')
plot_rgb.plot(v, [cmap(_)[1] for _ in v], color='g')
plot_rgb.plot(v, [cmap(_)[2] for _ in v], color='b')
plot_rgb.plot(v, [cmap(_)[0] for _ in v], color='#A60628')
plot_rgb.plot(v, [cmap(_)[1] for _ in v], color='#467821')
plot_rgb.plot(v, [cmap(_)[2] for _ in v], color='#348ABD')
plot_rgb.plot(v, [cmap_gray(_)[0] for _ in v], color='k', linestyle='--')
plot_rgb.set_ylabel('Luminance')
plot_rgb.set_ylim(-0.005, 1.005)
9 changes: 6 additions & 3 deletions gammapy/irf/effective_area_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ def plot_area_vs_energy(self, filename=None, show_save_energy=True):
plt.xlim(0.1, 100)
plt.ylim(1E3, 1E7)
plt.loglog()
plt.xlabel('Energy [TeV]')
plt.ylabel('Effective Area [m^2]')
plt.xlabel('Energy (TeV)')
plt.ylabel('Effective Area (m2)')
if filename is not None:
plt.savefig(filename)
log.info('Wrote {0}'.format(filename))
Expand Down Expand Up @@ -392,6 +392,9 @@ class EffectiveAreaTable2D(object):
from gammapy.datasets import load_aeff2D_fits_table
aeff2D = EffectiveAreaTable2D.from_fits(load_aeff2D_fits_table())
aeff2D.plot_energy_dependence()
plt.loglog()
plt.xlim(0.8, 100)
plt.ylim(2E4, 2E6)
"""

Expand Down Expand Up @@ -566,7 +569,7 @@ def plot_energy_dependence(self, ax=None, offset=None, energy=None, **kwargs):

plt.xlabel('Energy ({0})'.format(self.energy.unit))
plt.ylabel('Effective Area ({0})'.format(self.eff_area.unit))
plt.legend()
plt.legend(loc='lower right')

return ax

Expand Down
14 changes: 7 additions & 7 deletions gammapy/irf/psf_analytical.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ def plot_containment(self, fraction, filename=None, show_save_energy=True):
# Set up and compute data
containment = self._containment_radius_array(self.energy_hi, self.theta, fraction)
# Plotting
plt.figure(figsize=(8, 5))
plt.figure(figsize=(8, 6))
plt.imshow(containment.value, origin='lower', interpolation='None',
vmin=0.05, vmax=0.3)
vmin=0.1, vmax=0.2)

if show_save_energy:
# Log scale transformation for position of energy threshold
Expand All @@ -269,14 +269,14 @@ def plot_containment(self, fraction, filename=None, show_save_energy=True):
plt.text(x + 0.5, 0, 'Safe energy threshold: {0:3.2f}'.format(self.energy_thresh_lo))

# Axes labels and ticks, colobar
plt.xlabel('E [TeV]')
xticks = ["{0:3.2g}".format(_) for _ in self.energy_hi.value]
plt.xticks(np.arange(len(self.energy_hi)) + 0.5, xticks, size=9)
plt.ylabel('Theta [deg]')
plt.xlabel('E (TeV)')
xticks = ["{0:3.2g}".format(_) for _ in self.energy_hi.value[:-1]]
plt.xticks(np.arange(len(self.energy_hi)), xticks, size=9)
plt.ylabel('Theta (deg)')
yticks = ["{0:3.2g}".format(_) for _ in self.theta.value]
plt.yticks(np.arange(len(self.theta)), yticks, size=9)
cbar = plt.colorbar(fraction=0.1, pad=0.01)
cbar.set_label('Containment radius R{0:.0f} [deg]'.format(100 * fraction),
cbar.set_label('Containment radius R{0:.0f} (deg)'.format(100 * fraction),
labelpad=20)

if filename is not None:
Expand Down
1 change: 1 addition & 0 deletions gammapy/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
`gammapy.utils.random` or `gammapy.utils.wcs`.
Importing `gammapy.utils` directly is not useful.
"""
from .mpl_style import gammapy_mpl_style
22 changes: 22 additions & 0 deletions gammapy/utils/mpl_style.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst

from astropy.visualization import astropy_mpl_style

__all__ = ['gammapy_mpl_style']

gammapy_mpl_style = astropy_mpl_style
"""
Gammapy matplotlib plotting style.
"""

gammapy_mpl_style['axes.color_cycle'] = [
'#E24A33', # orange
'#348ABD', # blue
'#467821', # green
'#A60628', # red
'#7A68A6', # purple
'#CF4457', # pink
'#188487' # turquoise
]
gammapy_mpl_style['interactive'] = False
gammapy_mpl_style['axes.labelcolor'] = '#565656'

0 comments on commit 0c96597

Please sign in to comment.