vanallenlab / comut

CoMut is a Python library for visualizing genomic and phenotypic information via comutation plots
MIT License
89 stars 28 forks source link

add grid on comut plot #10

Closed mjko1210 closed 4 years ago

mjko1210 commented 4 years ago

Hi,

Is it possible to add grid to plots generated by add_continuous_data and add_continuous_data.

For example, I want to add grey grid lines like this plot. Screen Shot 2020-08-12 at 12 26 56 PM

Thanks for your advice!

jett-crowdis commented 4 years ago

Yes, this is possible by editing the individual axes. There is a function in matplotlib called ax.grid that will add gridlines to an axis object. By default this grid doesn't line up with the comut's patches, so you'll need to do some tinkering. Let's say I wanted to add such a grid to a categorical dataset named 'Mutation type'

from matplotlib.ticker import AutoMinorLocator # this function sets the location of the minor tick mark
minor_locator = AutoMinorLocator(2) # will place minor ticks in between major ticks

# set the axis minor tick locations to these positions
comut.axes['Mutation type'].yaxis.set_minor_locator(minor_locator)
comut.axes['Mutation type'].xaxis.set_minor_locator(minor_locator)

# add the grid
comut.axes['Mutation type'].grid(which='minor', color='black')

# the spines by default are off, so we need to add them back
comut.axes['Mutation type'].spines['left'].set_visible(True)
comut.axes['Mutation type'].spines['bottom'].set_visible(True)

The process is exactly the same for continuous data