Comments (3)
FWIW here's the existing code using gridspec
import penguins as pg
clipc = pg.read("./nmr/200804-6a-sc", 10, 1)
# make 2D spectrum 3x3 and projections 1x3, 3x1
gridspec_kw = {"width_ratios": [1, 3], "height_ratios": [1, 3]}
fig, axs = pg.subplots(2, 2, gridspec_kw=gridspec_kw)
# assign them to easy-to-remember variables
axblank, axf2, axf1, axmain = list(axs.flat)
# plot the 2D spectrum
clipc.stage(levels=2e5)
pg.mkplot(axmain, autolabel="nucl")
# get rid of the top-left empty space
axblank.remove()
# 1D projections
f2projp = clipc.f2projp()
f2projp.stage(color="blue")
pg.mkplot(axf2, xlabel="")
# the xlim should be set to the maximum and minimum chemical shift, i.e.
# we don't want overhang at the ends
p = f2projp.ppm_scale()
axf2.set_xlim((max(p), min(p)))
# get rid of x-axis
axf2.xaxis.set_visible(False)
axf2.spines["bottom"].set_visible(False)
# magic
from matplotlib import transforms
base_trfm = axf1.transData
rot_trfm = transforms.Affine2D().rotate_deg(90)
scale_trfm = transforms.Affine2D().scale(sx=1, sy=-1)
f1projp = clipc.f1projp()
f1projp.stage(color="blue", plot_options={"transform": scale_trfm + rot_trfm + base_trfm})
pg.mkplot(ax=axf1)
p = f1projp.ppm_scale()
axf1.set_ylim(max(p), min(p)) # this automatically inverts the y-axis
# Don't need to invert xaxis because mkplot() does it for us.
# axf1.invert_xaxis()
# However, we do need to disable the xaxis.
axf1.xaxis.set_visible(False)
axf1.spines["bottom"].set_visible(False)
# Let's put the y-axis ticks on the right.
axmain.yaxis.tick_right()
# And change the y-label position.
axmain.yaxis.label.set_rotation(0)
axmain.yaxis.label.set_horizontalalignment("left")
axmain.yaxis.label.set_verticalalignment("top")
axmain.yaxis.set_label_coords(1.02, 1)
# show the plot
pg.tight_layout()
pg.show()
from penguins.
Here's the code using axes_divider. This allows us to use subplots() to generate series of axes and then manipulate the individual axes after that.
fig, ax = pg.subplots(1, 1, figsize=(7, 7))
clipc.stage(levels=2e5)
pg.mkplot(ax=ax, autolabel="nucl")
### The only difference from before is that we use ax_divider instead of gridspec.
from mpl_toolkits.axes_grid1 import make_axes_locatable
ax_divider = make_axes_locatable(ax)
axf2 = ax_divider.append_axes("top", size="20%", pad="2%")
axf1 = ax_divider.append_axes("left", size="20%", pad="2%")
### Same code as before.
# 1D projections
f2projp = clipc.f2projp()
f2projp.stage(color="blue")
pg.mkplot(axf2, xlabel="")
# the xlim should be set to the maximum and minimum chemical shift, i.e.
# we don't want overhang at the ends
p = f2projp.ppm_scale()
axf2.set_xlim((max(p), min(p)))
# get rid of x-axis
axf2.xaxis.set_visible(False)
axf2.spines["bottom"].set_visible(False)
# magic
from matplotlib import transforms
base_trfm = axf1.transData
rot_trfm = transforms.Affine2D().rotate_deg(90)
scale_trfm = transforms.Affine2D().scale(sx=1, sy=-1)
f1projp = clipc.f1projp()
f1projp.stage(color="blue", plot_options={"transform": scale_trfm + rot_trfm + base_trfm})
pg.mkplot(ax=axf1)
p = f1projp.ppm_scale()
axf1.set_ylim(max(p), min(p)) # this automatically inverts the y-axis
# Don't need to invert xaxis because mkplot() does it for us.
# axf1.invert_xaxis()
# However, we do need to disable the xaxis.
axf1.xaxis.set_visible(False)
axf1.spines["bottom"].set_visible(False)
ax.yaxis.tick_right()
ax.yaxis.label.set_rotation(0)
ax.yaxis.label.set_horizontalalignment("left")
ax.yaxis.label.set_verticalalignment("top")
ax.yaxis.set_label_coords(1.02, 1)
pg.show()
from penguins.
There's also https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.axes.Axes.autoscale.html
set tight=True
to remove the padding added on either edge of the spectrum.
from penguins.
Related Issues (19)
- Complete documentation HOT 2
- Include shortforms for projection and slice methods
- Create examples for style_axes() HOT 1
- Allow fast way of setting xlabel/ylabel location (and yticks for 2D) HOT 2
- Empty the PHA anyway if mkplot() errors out
- Subclass Axes and add methods HOT 3
- Tie staging to an Axes instance? HOT 2
- Replace plot_options with **kwargs
- Write more unit tests for functions HOT 1
- Figure out how to do tests for plotting HOT 1
- Automatically add label to axes HOT 1
- Use a better github workflow
- Add support in pg.subplots2d() for height_ratios and width_ratios HOT 2
- awkward error message with ds.stage("1..2")
- plot spectra arrays HOT 1
- videos HOT 4
- Plot 1Ds inside 2Ds e.g. traces
- Create 'fake spectra' class so that data can be imported from other places
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from penguins.