@@ -211,3 +211,51 @@ def test_alias_methods(fake_pycirclize, tmp_path):
211211 circos = ax .bed (bed_path , plot = False )
212212 assert hasattr (circos , "sectors" )
213213 uplt .close (fig )
214+
215+
216+ def test_import_pycirclize_restores_savefig_settings ():
217+ """
218+ Importing pycirclize must not change how unrelated figures are saved.
219+
220+ ``pycirclize.config`` runs ``mpl.rcParams.update(...)`` at import time,
221+ setting ``savefig.bbox='tight'`` and ``savefig.pad_inches=0.5``. UltraPlot
222+ imports it lazily, so without a guard the first chord or radar plot in a
223+ session would silently pad and resize every figure saved afterwards.
224+ """
225+ import matplotlib as mpl
226+
227+ pytest .importorskip ("pycirclize" )
228+ watched = ("savefig.bbox" , "savefig.pad_inches" , "svg.fonttype" )
229+ before = {key : mpl .rcParams [key ] for key in watched }
230+ try :
231+ circlize_mod ._import_pycirclize ()
232+ assert {key : mpl .rcParams [key ] for key in watched } == before
233+ finally :
234+ for key , value in before .items ():
235+ mpl .rcParams [key ] = value
236+
237+
238+ def test_chord_diagram_does_not_resize_later_figures ():
239+ """
240+ A figure made after a chord diagram keeps the size it was asked for.
241+ """
242+ import matplotlib as mpl
243+
244+ pytest .importorskip ("pycirclize" )
245+ pandas = pytest .importorskip ("pandas" )
246+ numpy = pytest .importorskip ("numpy" )
247+
248+ watched = ("savefig.bbox" , "savefig.pad_inches" )
249+ before = {key : mpl .rcParams [key ] for key in watched }
250+ try :
251+ names = list ("ABCD" )
252+ matrix = pandas .DataFrame (
253+ numpy .arange (16 ).reshape (4 , 4 ) + 1 , index = names , columns = names
254+ )
255+ fig , ax = uplt .subplots (figwidth = "26mm" , figheight = "26mm" , proj = "polar" )
256+ ax .chord_diagram (matrix , ticks_interval = None )
257+ uplt .close (fig )
258+ assert {key : mpl .rcParams [key ] for key in watched } == before
259+ finally :
260+ for key , value in before .items ():
261+ mpl .rcParams [key ] = value
0 commit comments