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

Argument for time units in visualizations #106

Open
cing opened this issue Aug 31, 2017 · 4 comments
Open

Argument for time units in visualizations #106

cing opened this issue Aug 31, 2017 · 4 comments

Comments

@cing
Copy link

cing commented Aug 31, 2017

There's a few mentions about keeping track of the "frame -> time" conversions in the msmbuilder code, but I didn't see any issue about it there or here. Seems like MSME is a decent place to do this conversion for visualization purposes, maybe through some optional argument?

@msultan
Copy link
Collaborator

msultan commented Sep 1, 2017 via email

@jeiros
Copy link
Contributor

jeiros commented Sep 4, 2017

The way I've done this before is using FuncFormatter

You can just use the normal plotting functions and change them using a function that you define:

from matplotlib.ticker import FuncFormatter
import numpy as np
from msmexplorer import plot_trace

ts = .1
def to_ns(x, pos):
    return '{}'.format(x * ts)

a = np.random.random_sample(size=(500, 1))

ax, _ = plot_trace(a)
plt.show()

download1

ax, _ = plot_trace(a)
formatter = FuncFormatter(to_ns)
ax.xaxis.set_major_formatter(formatter)
plt.show()

download2

@cing
Copy link
Author

cing commented Sep 12, 2017

Wow, I was not aware this functionality existed. Are there any plots where this will not work? An interesting special case might be https://github.com/msmexplorer/msmexplorer/issues/105 , where the time colorbar is smoke and mirrors anyway?

Anyway, adding a frames_to_ns argument and two lines to each function doesn't seem too painful to me.

@jeiros
Copy link
Contributor

jeiros commented Sep 27, 2017

A minor improvement that I found out is that you can specify a third arg for the to_ns function so the timestep does not have to be known a priori (just be passed as a variable using functools.partial):

from matplotlib.ticker import FuncFormatter
import numpy as np
from msmexplorer import plot_trace
from matplotlib import pyplot as plt
from functools import partial


def to_ns(x, pos, ts):
    return '{}'.format(x * ts)

a = np.random.random_sample(size=(500, 1))

ax, _ = plot_trace(a)
formatter = FuncFormatter(partial(to_ns, ts=0.1))
ax.xaxis.set_major_formatter(formatter)
plt.show()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants