You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to save a figure to PDF format with aspect_ratio set in the theme, a TypeError is raised. The error occurs during the deepcopy operation when trying to adjust the plot's aspect ratio. The same plot saves successfully to PNG format, and saving to PDF works when aspect_ratio is not set. I am using the latest release version
Minimal Working Example:
importpandasaspdfromplotnineimportggplot, aes, geom_bar, theme_seaborn, theme, element_text, scale_y_log10importmathdata=pd.DataFrame({
'Throughput': ['A', 'A', 'B', 'B'],
'Type': ['X', 'Y', 'X', 'Y'],
'Value': [100, 1000, 200, 2000]
})
p1= (
ggplot(data, aes(x='Throughput', y='Value', fill='Type'))
+theme_seaborn('whitegrid')
+geom_bar(stat='identity', position='dodge')
+theme(axis_text=element_text(size=12))
+scale_y_log10(labels=lambdal: [f"$10^{{{int(math.log10(x))}}}$"forxinl])
+theme(aspect_ratio=0.5) # This causes the issue
)
# This will raise a TypeErrorp1.save('plot_with_aspect.pdf', bbox_inches='tight')
# While this works finep1.save('plot_with_aspect.png', bbox_inches='tight')
# And this also works (saving PDF without aspect_ratio)p2= (
ggplot(data, aes(x='Throughput', y='Value', fill='Type'))
+theme_seaborn('whitegrid')
+geom_bar(stat='identity', position='dodge')
+theme(axis_text=element_text(size=12))
+scale_y_log10(labels=lambdal: [f"$10^{{{int(math.log10(x))}}}$"forxinl])
# aspect_ratio removed
)
p2.save('plot_without_aspect.pdf', bbox_inches='tight')
When trying to save a figure to PDF format with
aspect_ratio
set in the theme, a TypeError is raised. The error occurs during the deepcopy operation when trying to adjust the plot's aspect ratio. The same plot saves successfully to PNG format, and saving to PDF works whenaspect_ratio
is not set. I am using the latest release versionMinimal Working Example:
Error message:
TypeError: cannot pickle 'generator' object
The error traceback shows the issue occurs in the layout engine during the PDF save process.
Workaround:
Instead of using
theme(aspect_ratio=0.5)
, you can achieve the same result by setting the width and height directly in the save function:The text was updated successfully, but these errors were encountered: