Closed pwwang closed 1 year ago
@pwwang, do you have a simplified example that triggered the error.
If we generate the minor_breaks
using np.array
, then the error on the title raised:
import pandas as pd
import plotnine as p9
import numpy as np
df = pd.DataFrame({'x': [1, 10, 100], 'y': [3, 1, 2]})
p = p9.ggplot(df, p9.aes(x='x', y='y')) + p9.scale_x_log10(
minor_breaks=np.array([10**0.5, 10**1.5, 10**2.5])
# ^^^^^^^^
)
p # ValueError
It's fine if we fallback to a list
:
import pandas as pd
import plotnine as p9
import numpy as np
df = pd.DataFrame({'x': [1, 10, 100], 'y': [3, 1, 2]})
p = p9.ggplot(df, p9.aes(x='x', y='y')) + p9.scale_x_log10(
minor_breaks=[10**0.5, 10**1.5, 10**2.5]
)
p # ValueError
But the minor breaks are wrong:
That's why we need to modify line 1020.
There are other similar coding styles in this scale.py
:
https://github.com/has2k1/plotnine/blob/2405442dfd59f966ad98a6461ef870ea8e406235/plotnine/scales/scale.py#L573 https://github.com/has2k1/plotnine/blob/2405442dfd59f966ad98a6461ef870ea8e406235/plotnine/scales/scale.py#L1042
I am not sure if there are other similar situations in other files.
I understand you expected them to be plain python objects (list), but sometimes they could be a numpy array or a pandas Series.
By the way, for now, I have to monkey-patch plotnine to get plotnine-prism to work:
https://github.com/has2k1/plotnine/blob/2405442dfd59f966ad98a6461ef870ea8e406235/plotnine/scales/scale.py#L1012-L1030
self.minor_breaks
could be a numpy array, which is causing this error.would fix it.
Also, line 1020 should be: