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

Retain latex label when slicing DataFrame to Series #253

Closed
AdamOrmondroyd opened this issue Jan 19, 2023 · 3 comments · Fixed by #304
Closed

Retain latex label when slicing DataFrame to Series #253

AdamOrmondroyd opened this issue Jan 19, 2023 · 3 comments · Fixed by #304
Milestone

Comments

@AdamOrmondroyd
Copy link
Collaborator

When a dataframe of nested samples is sliced to a smaller dataframe, it retains the latex labels, e.g:

>>> ns[['x0']]
                          x0
labels                 $x_0$
     weights
0    0.000000e+00   0.839566
1    1.088407e-308  0.711607
2    4.830017e-301 -0.703718
3    6.951167e-262  0.980678
4    7.661544e-241  0.727711
...                      ...
>>> ns[['x0']].get_labels()
array(['$x_0$'], dtype=object)

However, if it is sliced to a series, the latex labels are lost:

>>> ns['x0']
      weights
0     0.000000e+00     0.839566
1     1.088407e-308    0.711607
2     4.830017e-301   -0.703718
3     6.951167e-262    0.980678
4     7.661544e-241    0.727711
                         ...
>>> ns['x0'].get_labels()
array([0.00000000e+000, 1.08840734e-308, 4.83001654e-301, ...,
       2.31405635e-001, 2.33317335e-001, 2.38103982e-001])

This is unfortunate, as all the plotting uses the series rather than dataframes, and it would be nice if the axes and legends could use the latex labels where they exist.

>>> ns.plot.kde_2d('x0', 'x1')

Screenshot 2023-01-19 at 12 32 41

@AdamOrmondroyd AdamOrmondroyd changed the title Retain latex label when slicing Retain latex label when slicing DataFrame to Series Jan 19, 2023
@AdamOrmondroyd
Copy link
Collaborator Author

I think the degenerate meaning of "labels" is quite confusing

@AdamOrmondroyd
Copy link
Collaborator Author

If one instead slices using the full multiindex, then this is used for the axis label:

>>> ns.plot.kde_2d(('x0', '$x_0$'), ('x1', '$x_1$'))

image

I believe the axis title matches the Series.name, so perhaps we could do something clever here?

@AdamOrmondroyd
Copy link
Collaborator Author

If NestedSamples are cast to DataFrame, then labels are retained after slicing, and shown in e.g.

ns['x0'].plot.kde()
df = pd.DataFrame(ns)
df['x0'].plot.kde()
plt.show()

NestedSamples
Screenshot 2023-02-10 at 16 42 04

DataFrame
Screenshot 2023-02-10 at 16 42 52

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

Successfully merging a pull request may close this issue.

2 participants