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

Refactor plot styling to add a base style; set PDF truetype #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ Versioning <http://semver.org/>`__. The changelog format is inspired by

`Unreleased <https://github.com/smtg-ucl/galore/compare/0.6.1...HEAD>`__
-------------------------------------------------------------------------

- Updated setup.py to add a [vasp] extra; this handles Pymatgen
installation which can be tricky on older Python versions.
- Update citation information, add to README
- Use a default base stylesheet to make more compatible PDF files

`[0.6.1] <https://github.com/smtg-ucl/galore/compare/0.6.0...0.6.1>`__ - 2018-11-19
-----------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include README.rst CHANGELOG.rst LICENSE CITATION.cff
include test/test*.py
recursive-include galore/data cross_sections.json cross_sections_ups.json cross_sections_haxpes.json scofield_data.db
recursive-include galore/data cross_sections.json cross_sections_ups.json cross_sections_haxpes.json scofield_data.db galore_base.mplstyle
include test/DOSCAR.1 test/test_xy_data.csv test/json_test.json
recursive-include test/CaF2 ir_lda_700.txt raman_lda_500.dat
recursive-include test/CdTe CdTe.gpw
Expand Down
11 changes: 8 additions & 3 deletions galore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,23 @@

from __future__ import print_function

import os.path
from itertools import repeat
from collections import OrderedDict
from itertools import repeat
import logging

from math import sqrt, log
import os.path
from os.path import pardir
from os.path import join as path_join
from pkg_resources import resource_filename

import numpy as np
from scipy.interpolate import interp1d

import galore.formats
from galore.cross_sections import get_cross_sections, cross_sections_info

base_style = resource_filename(__name__,
path_join('data', 'galore_base.mplstyle'))

def auto_limits(data_1d, padding=0.05):
"""Return limiting values outside data range
Expand Down
18 changes: 12 additions & 6 deletions galore/cli/galore.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# If not, see <http://www.gnu.org/licenses/>. #
# #
###############################################################################
import os

import argparse
from collections import OrderedDict
from json import load as json_load
Expand All @@ -39,7 +39,6 @@
except ImportError:
has_matplotlib = False


def main():
logging.basicConfig(filename='galore.log', level=logging.INFO)
console = logging.StreamHandler()
Expand Down Expand Up @@ -86,9 +85,13 @@ def pdos_from_files(return_plt=False, **kwargs):
# For plotting and writing, "None" means "write to screen"
# while False means "do nothing"
if kwargs['plot'] or kwargs['plot'] is None:
import matplotlib.pyplot
style_list = [galore.base_style]

if 'style' in kwargs and kwargs['style'] is not None:
import matplotlib.pyplot
matplotlib.pyplot.style.use(kwargs['style'])
style_list += kwargs['style']
matplotlib.pyplot.style.use(style_list)

plt = galore.plot.plot_pdos(pdos_plotting_data,
**kwargs) # flipx is included in kwargs

Expand Down Expand Up @@ -155,9 +158,12 @@ def simple_dos_from_files(return_plt=False, **kwargs):
if not has_matplotlib:
print("Can't plot, no Matplotlib")
else:
import matplotlib.pyplot
style_list = [galore.base_style]
if 'style' in kwargs and kwargs['style'] is not None:
import matplotlib.pyplot
matplotlib.pyplot.style.use(kwargs['style'])
style_list += kwargs['style']
matplotlib.pyplot.style.use(style_list)

plt = galore.plot.plot_tdos(x_values, broadened_data, **kwargs)
if kwargs['ylabel'] is not None:
plt.ylabel(kwargs['ylabel'])
Expand Down
5 changes: 3 additions & 2 deletions galore/cli/galore_plot_cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import logging
import numpy as np
from matplotlib import pyplot as plt
plt.style.use('seaborn-colorblind')

from galore.cross_sections import get_cross_sections_scofield

Expand Down Expand Up @@ -67,8 +66,10 @@ def run(elements, emin=1, emax=10, megabarn=False, size=None, output=None,
energies = np.linspace(emin, emax, 200)
cross_sections = get_cross_sections_scofield(energies, elements)

style_list = [galore.base_style]
if style is not None:
plt.style.use(style)
style_list += style
plt.style.use(style_list)

if size is None:
fig = plt.figure()
Expand Down
1 change: 1 addition & 0 deletions galore/data/galore_base.mplstyle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pdf.fonttype = 42 # Use truetype; makes PDF files easier to modify