Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Closed
Milestone
Description
Bug report
During computation of tight_layout of subplots containing a histogram one gets a ValueError in bezier.py:35: Given lines do not intersect. Please verify that the angles are not equal or differ by 180 degrees.
Could be related to#6076
See the attached script and csv files to reproduce the bug. I have marked three FIXME code lines, that are all conditions for the bug to be triggered.
- use subplots with more than one axes.
- use annotations with an arrowprops argument.
This seems to be a regression in matplotlib 3, since the LTS version is running fine.
test files:files.zip
importmatplotlib.pyplotaspltimportnumpyasnpdefplot_1D_histogram_trajectories(data,centers=None,dtrajs=None,max_traj_length=200,ax=None):forn,_trajinenumerate(data):ax.hist(_traj,bins=30,alpha=.33,density=True,color='C{}'.format(n))ylims=ax.get_ylim()xlims=ax.get_xlim()forn,_trajinenumerate(data):ax.plot(_traj[:min(len(_traj),max_traj_length)],np.linspace(*ylims,min(len(_traj),max_traj_length)),alpha=0.6,color='C{}'.format(n),label='traj {}'.format(n))ax.plot(centers[dtrajs[n][:min(len(_traj),max_traj_length)]],np.linspace(*ylims,min(len(_traj),max_traj_length)),'.-',alpha=.6,label='dtraj {}'.format(n),linewidth=.3)ax.annotate('',xy=(0.85*xlims[1],0.7*ylims[1]),xytext=(0.85*xlims[1],0.3*ylims[1]),# FIXME: if one omits this argument, it succeedsarrowprops=dict(), )ax.text(0.86*xlims[1],0.5*ylims[1],'$x(time)$',ha='left',va='center',rotation=90)ax.legend(loc=2)# FIXME: if only one subfigure is created it succeedsfig,axes=plt.subplots(1,2,figsize=(10,4))data= [np.loadtxt('data.csv')]dtraj=np.loadtxt('dtraj.csv').astype(int)centers=np.loadtxt('centers.csv')plot_1D_histogram_trajectories(data,centers=centers,dtrajs=[dtraj],ax=axes[0])axes[1].plot(x=np.arange(10),y=np.arange(10))fig.tight_layout()
leads to
File "/home/mi/marscher/sources/pyemma_tutorials/notebooks/minimal_example.py", line 34, in <module> fig.tight_layout() File "/srv/public/marscher/miniconda3/envs/nbtut/lib/python3.6/site-packages/matplotlib/figure.py", line 2374, in tight_layout pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect) File "/srv/public/marscher/miniconda3/envs/nbtut/lib/python3.6/site-packages/matplotlib/tight_layout.py", line 366, in get_tight_layout_figure pad=pad, h_pad=h_pad, w_pad=w_pad) File "/srv/public/marscher/miniconda3/envs/nbtut/lib/python3.6/site-packages/matplotlib/tight_layout.py", line 115, in auto_adjust_subplotpars tight_bbox_raw = union([ax.get_tightbbox(renderer) for ax in subplots File "/srv/public/marscher/miniconda3/envs/nbtut/lib/python3.6/site-packages/matplotlib/tight_layout.py", line 116, in <listcomp> if ax.get_visible()]) File "/srv/public/marscher/miniconda3/envs/nbtut/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 4396, in get_tightbbox bbox = a.get_tightbbox(renderer) File "/srv/public/marscher/miniconda3/envs/nbtut/lib/python3.6/site-packages/matplotlib/artist.py", line 271, in get_tightbbox bbox = self.get_window_extent(renderer) File "/srv/public/marscher/miniconda3/envs/nbtut/lib/python3.6/site-packages/matplotlib/text.py", line 2425, in get_window_extent bboxes.append(self.arrow_patch.get_window_extent()) File "/srv/public/marscher/miniconda3/envs/nbtut/lib/python3.6/site-packages/matplotlib/patches.py", line 548, in get_window_extent return self.get_path().get_extents(self.get_transform()) File "/srv/public/marscher/miniconda3/envs/nbtut/lib/python3.6/site-packages/matplotlib/patches.py", line 4228, in get_path _path, fillable = self.get_path_in_displaycoord() File "/srv/public/marscher/miniconda3/envs/nbtut/lib/python3.6/site-packages/matplotlib/patches.py", line 4258, in get_path_in_displaycoord self.get_mutation_aspect()) File "/srv/public/marscher/miniconda3/envs/nbtut/lib/python3.6/site-packages/matplotlib/patches.py", line 3218, in __call__ return self.transmute(path, mutation_size, linewidth) File "/srv/public/marscher/miniconda3/envs/nbtut/lib/python3.6/site-packages/matplotlib/patches.py", line 3718, in transmute tail_width / 2.) File "/srv/public/marscher/miniconda3/envs/nbtut/lib/python3.6/site-packages/matplotlib/bezier.py", line 381, in get_parallels cos_t2, sin_t2) File "/srv/public/marscher/miniconda3/envs/nbtut/lib/python3.6/site-packages/matplotlib/bezier.py", line 35, in get_intersection raise ValueError("Given lines do not intersect. Please verify that "ValueError: Given lines do not intersect. Please verify that the angles are not equal or differ by 180 degrees.
Expected outcome
It works, if the arrowprops are omitted, which means not to draw an arrow.
Matplotlib version
- Operating system: linux64
- Matplotlib version: 3.0.2
- Matplotlib backend (
print(matplotlib.get_backend())
): module://backend_interagg - Python version: 3.6
- Other libraries: see attachedconda_list.txt
Installed with conda from conda-forge.
Metadata
Metadata
Assignees
Labels
No labels