Skip to content

Commit

Permalink
gui changes for consistency with recent pyside etc on high DPI
Browse files Browse the repository at this point in the history
  • Loading branch information
cmbant committed May 20, 2021
1 parent 2b4646a commit be92aa9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 32 deletions.
2 changes: 1 addition & 1 deletion docs/source/gui.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Install PySide2 from pip using::
You can also use `Anaconda <https://www.anaconda.com/distribution/>`_,
making a consistent new environment from conda-forge (which includes PySide2) using::

conda create -n py37forge -c conda-forge python=3.7 scipy pandas matplotlib PySide2
conda create -n py39forge -c conda-forge python=3.9 scipy pandas matplotlib PySide2

(note that PySide2 is currently not included in the default Anaconda packages).

Expand Down
13 changes: 9 additions & 4 deletions getdist/gui/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
if not os.path.exists(os.path.join(sys.prefix, 'conda-meta')):
print('Using Anaconda is probably the most reliable method')
print("E.g. make and use a new environment using conda-forge")
print('conda create -n py37forge -c conda-forge python=3.7 scipy pandas matplotlib PySide2')
print('conda create -n py39forge -c conda-forge python=3.9 scipy pandas matplotlib PySide2')

sys.exit(-1)

Expand Down Expand Up @@ -133,6 +133,7 @@ def __init__(self, app, ini=None, base_dir=None):
self.ConfigDlg = None
self.plotSettingDlg = None
self.custom_plot_settings = {}
self.preview_settings = {'constrained_layout': True, 'direct_scaling': True}

self.setAttribute(Qt.WA_DeleteOnClose)
if os.name == 'nt':
Expand Down Expand Up @@ -1476,6 +1477,7 @@ def plotData(self):
items_y = self.getYParams()
self.plotter.settings = copy.copy(self.default_plot_settings)
self.plotter.settings.__dict__.update(self.custom_plot_settings)
self.plotter.settings.__dict__.update(self.preview_settings)

script = "from getdist import plots\n"
if self.script_plot_module != 'getdist.plots':
Expand Down Expand Up @@ -1531,8 +1533,9 @@ def plotData(self):
logging.debug("Plotting with roots = %s" % str(roots))

# fudge factor of 0.8 seems to help with overlapping labels on retina Mac.
height = self.plotWidget.height() / self.logicalDpiX() * 0.8
width = self.plotWidget.width() / self.logicalDpiX() * 0.8
# seem to have to render at the dpi-scaled small size, as then scaled up
height = self.plotWidget.height() / self.logicalDpiX() / self.devicePixelRatio()
width = self.plotWidget.width() / self.logicalDpiX() / self.devicePixelRatio()

def setSizeForN(cols, rows):
if self.plotter.settings.fig_width_inch is not None:
Expand Down Expand Up @@ -1850,6 +1853,7 @@ def updateScriptPreview(self, plotter):
# ==============================================================================


# noinspection PyArgumentList
class DialogTextOutput(QDialog):
def __init__(self, parent, text=None):
QDialog.__init__(self, parent, Qt.WindowSystemMenuHint | Qt.WindowTitleHint | Qt.WindowCloseButtonHint)
Expand Down Expand Up @@ -1984,6 +1988,7 @@ def __init__(self, parent, stats, summary, root):
self.setWindowTitle(self.tr('Convergence stats: ' + root))
# noinspection PyArgumentList
h = min(QApplication.desktop().screenGeometry().height() * 4 / 5, 1200)
# noinspection PyArgumentList
self.resize(700, h)


Expand All @@ -1998,7 +2003,7 @@ def __init__(self, parent, PCA_text, root):
self.setWindowTitle(self.tr('PCA constraints for: ' + root))
# noinspection PyArgumentList
h = min(QApplication.desktop().screenGeometry().height() * 4 / 5, 800)
self.resize(500, h)
self.resize(500)


# ==============================================================================
Expand Down
60 changes: 33 additions & 27 deletions getdist/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import warnings
import logging
from types import MappingProxyType
from typing import Mapping, Sequence, Union
from typing import Mapping, Sequence, Union, Optional

if 'ipykern' not in matplotlib.rcParams['backend'] and \
'linux' in sys.platform and os.environ.get('DISPLAY', '') == '':
Expand Down Expand Up @@ -67,7 +67,8 @@ class GetDistPlotSettings(_BaseObject):
:ivar colormap: a `Matplotlib color map <https://www.scipy.org/Cookbook/Matplotlib/Show_colormaps>`_ for shading
:ivar colormap_scatter: a Matplotlib `color map <https://www.scipy.org/Cookbook/Matplotlib/Show_colormaps>`_
for 3D scatter plots
:ivar constrained_layout: use matplotlib's constrained-layout to fit plots within the figure and avoid overlaps
:ivar constrained_layout: use matplotlib's constrained-layout to fit plots within the figure and avoid overlaps.
(Note this setting has no effect in the GetDist GUI preview, as always on there)
:ivar fig_width_inch: The width of the figure in inches
:ivar figure_legend_frame: draw box around figure legend
:ivar figure_legend_loc: The location for the figure legend
Expand Down Expand Up @@ -101,9 +102,10 @@ class GetDistPlotSettings(_BaseObject):
:ivar progress: write out some status
:ivar scaling: True to scale down fonts and lines for smaller subplots; False to use fixed sizes.
:ivar scaling_max_axis_size: font sizes will only be scaled for subplot widths (in inches) smaller than this.
:ivar scaling_factor: factor by which to multiply the different of the axis size to the reference size when
:ivar scaling_factor: factor by which to multiply the difference of the axis size to the reference size when
scaling font sizes
:ivar scaling_reference_size: axis width (in inches) at which font sizes are specified.
:ivar direct_scaling: True to directly scale the font size with the axis size for small axes (can be very small)
:ivar scatter_size: size of points in "3D" scatter plots
:ivar shade_level_scale: shading contour colors are put at [0:1:spacing]**shade_level_scale
:ivar shade_meanlikes: 2D shading uses mean likelihoods rather than marginalized density
Expand Down Expand Up @@ -146,8 +148,9 @@ def __init__(self, subplot_size_inch=2, fig_width_inch=None):
"""
self.scaling = True
self.scaling_reference_size = 3.5 # reference subplot size for font sizes etc.
self.scaling_max_axis_size = self.scaling_reference_size
self.scaling_max_axis_size: Optional[float] = self.scaling_reference_size
self.scaling_factor = 2
self.direct_scaling = False # if true just scale directly with the axes size

self.plot_meanlikes = False
self.prob_label = None
Expand All @@ -156,10 +159,10 @@ def __init__(self, subplot_size_inch=2, fig_width_inch=None):
self.prob_y_ticks = False
self.norm_1d_density = False
# : line styles/colors
self.line_styles = ['-k', '-r', '-b', '-g', '-m', '-c', '-y', '--k', '--r', '--b', '--g', '--m']
self.line_styles: Sequence[str] = ['-k', '-r', '-b', '-g', '-m', '-c', '-y', '--k', '--r', '--b', '--g', '--m']

self.plot_args = None
self.line_dash_styles = {'--': (3, 2), '-.': (4, 1, 1, 1)}
self.line_dash_styles: Mapping[str, Sequence[float]] = {'--': (3, 2), '-.': (4, 1, 1, 1)}
self.line_labels = True
self.num_shades = 80
self.shade_level_scale = 1.8 # contour levels at [0:1:spacing]**shade_level_scale
Expand All @@ -175,57 +178,57 @@ def __init__(self, subplot_size_inch=2, fig_width_inch=None):
self.colormap = "Blues"
self.colormap_scatter = "jet"
self.colorbar_tick_rotation = None
self.colorbar_label_pad = 0
self.colorbar_label_rotation = -90
self.colorbar_axes_fontsize = 11
self.colorbar_label_pad: float = 0
self.colorbar_label_rotation: float = -90
self.colorbar_axes_fontsize: float = 11

self.subplot_size_inch = subplot_size_inch
self.subplot_size_inch: float = subplot_size_inch
self.subplot_size_ratio = None

self.param_names_for_labels = None

self.legend_colored_text = False
self.legend_loc = 'best'
self.legend_frac_subplot_margin = 0.05
self.legend_fontsize = 12
self.legend_fontsize: float = 12
self.legend_frame = True
self.legend_rect_border = False

self.figure_legend_loc = 'upper center'
self.figure_legend_frame = True
self.figure_legend_ncol = 0

self.linewidth = 1
self.linewidth: float = 1
self.linewidth_contour = 0.6
self.linewidth_meanlikes = 0.5

self.num_plot_contours = 2
self.num_plot_contours: int = 2
self.solid_contour_palefactor = 0.6
self.solid_colors = ['#006FED', '#E03424', 'gray', '#009966', '#000866', '#336600', '#006633', 'm', 'r']
self.alpha_filled_add = 0.85
self.alpha_factor_contour_lines = 0.5
self.shade_meanlikes = False

self.axes_fontsize = 11
self.axes_labelsize = 14
self.axes_fontsize: float = 11
self.axes_labelsize: float = 14

self.axis_marker_color = 'gray'
self.axis_marker_ls = '--'
self.axis_marker_lw = 0.5

self.axis_tick_powerlimits = (-4, 5)
self.axis_tick_max_labels = 7
self.axis_tick_step_groups = [[1, 2, 5, 10], [2.5, 3, 4, 6, 8], [1.5, 7, 9]]
self.axis_tick_x_rotation = 0
self.axis_tick_y_rotation = 0
self.axis_tick_powerlimits: Sequence[int] = (-4, 5)
self.axis_tick_max_labels: int = 7
self.axis_tick_step_groups: Sequence[Sequence[float]] = [[1, 2, 5, 10], [2.5, 3, 4, 6, 8], [1.5, 7, 9]]
self.axis_tick_x_rotation: float = 0
self.axis_tick_y_rotation: float = 0

self.scatter_size = 3
self.scatter_size: float = 3

self.fontsize = 12
self.fontsize: float = 12

self.title_limit = 0
self.title_limit: int = 0 # which limit (1,2..) to plot in the title
self.title_limit_labels = True
self.title_limit_fontsize = None
self.title_limit_fontsize: Optional[float] = None
self._fail_on_not_exist = True

def _numerical_fontsize(self, size):
Expand All @@ -240,7 +243,10 @@ def scaled_fontsize(self, ax_size, var, default=None):
if not self.scaling or self.scaling_max_axis_size is not None and not self.scaling_max_axis_size:
return var
if self.scaling_max_axis_size is None or ax_size < (self.scaling_max_axis_size or self.scaling_reference_size):
return max(5, var + self.scaling_factor * (ax_size - self.scaling_reference_size))
if self.direct_scaling:
return var * ax_size / self.scaling_reference_size
else:
return max(5, var + self.scaling_factor * (ax_size - self.scaling_reference_size))
else:
return var + 2 * (self.scaling_max_axis_size - self.scaling_reference_size)

Expand Down Expand Up @@ -1432,7 +1438,7 @@ def _no_y_ticklabels(ax):
ax.yaxis.offsetText.set_visible(False)

def set_axes(self, params=(), lims=None, do_xlabel=True, do_ylabel=True, no_label_no_numbers=False, pos=None,
color_label_in_axes=False, ax=None, **other_args):
color_label_in_axes=False, ax=None, **_other_args):
"""
Set the axis labels and ticks, and various styles. Do not usually need to call this directly.
Expand All @@ -1446,7 +1452,7 @@ def set_axes(self, params=(), lims=None, do_xlabel=True, do_ylabel=True, no_labe
the third parameter
:param ax: optional :class:`~matplotlib:matplotlib.axes.Axes` instance (or y,x subplot coordinate)
to add to (defaults to current plot or the first/main plot if none)
:param other_args: Not used, just quietly ignore so that set_axes can be passed general kwargs
:param _other_args: Not used, just quietly ignore so that set_axes can be passed general kwargs
:return: an :class:`~matplotlib:matplotlib.axes.Axes` instance
"""
ax = self.get_axes(ax)
Expand Down

0 comments on commit be92aa9

Please sign in to comment.