Source code for schrodinger.application.desmond.event_analysis.pl_image_tools
from mpl_toolkits import axes_grid1 as mpl_axes_grid1
from schrodinger.application.desmond import report_helper
[docs]def add_histo(ax, data, color, na_color='#D9D9D9', grey_axes_decorations=True):
"""
Add a histogram to the right of the given axes
:param ax: The axes to add the histogram to
:type ax: `matplotlib.axes.Axes`
:param data: The data to calculate the histogram for
:type data: list
:param color: The color for the histogram bars
:type color: str
:param na_color: The color for the "NA" text if no data is present.
Defaults to light gray.
:type na_color: str
:param grey_axes_decorations: If True, the spines, ticks, and axis labels
will be colored dark gray. If False, they will be colored the default
matplotlib colors.
:type grey_axes_decorations: bool
:return: The newly added histogram axes
:rtype: `matplotlib.axes.Axes`
"""
divider = mpl_axes_grid1.make_axes_locatable(ax)
hax = divider.append_axes("right", 1.2, pad=0.1, sharey=ax)
if data.count(0) == len(data):
hax.set_xlim(xmax=1)
color = 'white'
hax.text(0.5,
0.5,
'NA',
size=18,
color=na_color,
horizontalalignment='center',
verticalalignment='center')
hax.hist(data,
bins=10,
orientation='horizontal',
density=True,
rwidth=0.7,
color=color,
edgecolor="none")
hax.xaxis.set_visible(False)
hax.tick_params('y', labelleft=False, labelright=False)
if grey_axes_decorations:
report_helper.change_plot_colors(hax)
return hax