Closed
Description
In previous versions of matplotlib, e.g. 2.0.2, it was possible to call a Normalize
instance with a dataframe as input
import matplotlib.pyplot as plt
import pandas as pd
df = pd.DataFrame([[1,3],[5,7]], columns=list("AB"))
norm = plt.Normalize(0,10)
print(norm(df))
this is useful e.g. for directly applying a norm to a dataframe to later style it with a colormap or to get the values synchronized to a plot. E.g.
normed = df.apply(norm)
print(normed)
A B
0 0.1 0.3
1 0.5 0.7
This is not possible any more with matplotlib 2.2
The above code run in matplotlib 2.2 produces the following error
Traceback (most recent call last):
File "untitled0.py", line 13, in <module>
print(norm(df))
File "...\lib\site-packages\matplotlib\colors.py", line 938, in __call__
result, is_scalar = self.process_value(value)
File "...\lib\site-packages\matplotlib\colors.py", line 924, in process_value
result = np.ma.array(data, mask=mask, dtype=dtype, copy=True)
File "...\lib\site-packages\numpy\ma\core.py", line 6299, in array
ndmin=ndmin, shrink=shrink, order=order)
File "...\lib\site-packages\numpy\ma\core.py", line 2809, in __new__
order=order, subok=True, ndmin=ndmin)
TypeError: float() argument must be a string or a number
Now one my easily work around this, e.g. via
norm = plt.Normalize(0,10)
print(norm(df.values))
normed = df.apply(lambda x: norm(x.values))
print(normed)
but given that it has been possible to call the norm in previous versions, it feels like a regression.
Did this only work by coincidence? Was there a reason to remove that feature? Should it be reintroduced or is there a reason not to allow Normalize
being called with a DataFrame?
Metadata
Metadata
Assignees
Labels
No labels