Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning - save pgfs with text and dates #10617

Closed
Phibedy opened this issue Feb 27, 2018 · 4 comments

Comments

Projects
None yet
3 participants
@Phibedy
Copy link

commented Feb 27, 2018

Bug report

Can't save pgfs with text and dates, saving

  • plot + scatter with dates works
  • text in cartesian coordinate system works

Code for reproduction

import pandas as pd
from datetime import datetime
import matplotlib.pyplot as plt

data = pd.DataFrame(index=[datetime(year=2016,month=1,day=1),datetime(year=2017,month=1,day=1)]).resample("M").sum()
data["v"]=range(len(data))
data["v"].plot()
plt.scatter(datetime(year=2016,month=6,day=1),5,color="red")
plt.text(datetime(year=2016,month=6,day=1), 5, 1, color="black", fontsize=12)
plt.savefig("/tmp/foo.pgf")

Actual outcome
Image image looks like
image
The console says: ValueError: object too deep for desired array but the pgf is saved


# If applicable, paste the console output here
#
ValueError                                Traceback (most recent call last)
<ipython-input-3-ce8d30b8a616> in <module>()
      9 plt.scatter(datetime(year=2016,month=6,day=1),5,color="red")
     10 plt.text(datetime(year=2016,month=6,day=1), 5, 1, color="black", fontsize=12)
---> 11 plt.savefig("/tmp/foo.pgf")

/usr/local/lib/python3.5/dist-packages/matplotlib/pyplot.py in savefig(*args, **kwargs)
    695 def savefig(*args, **kwargs):
    696     fig = gcf()
--> 697     res = fig.savefig(*args, **kwargs)
    698     fig.canvas.draw_idle()   # need this if 'transparent=True' to reset colors
    699     return res

/usr/local/lib/python3.5/dist-packages/matplotlib/figure.py in savefig(self, *args, **kwargs)
   1570             self.set_frameon(frameon)
   1571 
-> 1572         self.canvas.print_figure(*args, **kwargs)
   1573 
   1574         if frameon:

/usr/local/lib/python3.5/dist-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2242                 orientation=orientation,
   2243                 bbox_inches_restore=_bbox_inches_restore,
-> 2244                 **kwargs)
   2245         finally:
   2246             if bbox_inches and restore_bbox:

/usr/local/lib/python3.5/dist-packages/matplotlib/backends/backend_pgf.py in print_pgf(self, fname_or_fh, *args, **kwargs)
    859         if is_string_like(fname_or_fh):
    860             with codecs.open(fname_or_fh, "w", encoding="utf-8") as fh:
--> 861                 self._print_pgf_to_fh(fh, *args, **kwargs)
    862         elif is_writable_file_like(fname_or_fh):
    863             fh = codecs.getwriter("utf-8")(fname_or_fh)

/usr/local/lib/python3.5/dist-packages/matplotlib/backends/backend_pgf.py in _print_pgf_to_fh(self, fh, *args, **kwargs)
    840                                      RendererPgf(self.figure, fh),
    841                                      bbox_inches_restore=_bbox_inches_restore)
--> 842         self.figure.draw(renderer)
    843 
    844         # end the pgfpicture environment

/usr/local/lib/python3.5/dist-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     61     def draw_wrapper(artist, renderer, *args, **kwargs):
     62         before(artist, renderer)
---> 63         draw(artist, renderer, *args, **kwargs)
     64         after(artist, renderer)
     65 

/usr/local/lib/python3.5/dist-packages/matplotlib/figure.py in draw(self, renderer)
   1141 
   1142             mimage._draw_list_compositing_images(
-> 1143                 renderer, self, dsu, self.suppressComposite)
   1144 
   1145             renderer.close_group('figure')

/usr/local/lib/python3.5/dist-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, dsu, suppress_composite)
    137     if not_composite or not has_images:
    138         for zorder, a in dsu:
--> 139             a.draw(renderer)
    140     else:
    141         # Composite any adjacent images together

/usr/local/lib/python3.5/dist-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     61     def draw_wrapper(artist, renderer, *args, **kwargs):
     62         before(artist, renderer)
---> 63         draw(artist, renderer, *args, **kwargs)
     64         after(artist, renderer)
     65 

/usr/local/lib/python3.5/dist-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)
   2407             renderer.stop_rasterizing()
   2408 
-> 2409         mimage._draw_list_compositing_images(renderer, self, dsu)
   2410 
   2411         renderer.close_group('axes')

/usr/local/lib/python3.5/dist-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, dsu, suppress_composite)
    137     if not_composite or not has_images:
    138         for zorder, a in dsu:
--> 139             a.draw(renderer)
    140     else:
    141         # Composite any adjacent images together

/usr/local/lib/python3.5/dist-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     61     def draw_wrapper(artist, renderer, *args, **kwargs):
     62         before(artist, renderer)
---> 63         draw(artist, renderer, *args, **kwargs)
     64         after(artist, renderer)
     65 

/usr/local/lib/python3.5/dist-packages/matplotlib/text.py in draw(self, renderer)
    800                     textrenderer.draw_text(gc, x, y, clean_line,
    801                                            textobj._fontproperties, angle,
--> 802                                            ismath=ismath, mtext=mtext)
    803 
    804         gc.restore()

/usr/local/lib/python3.5/dist-packages/matplotlib/backends/backend_pgf.py in draw_text(self, gc, x, y, s, prop, angle, ismath, mtext)
    688             # if text anchoring can be supported, get the original coordinates
    689             # and add alignment information
--> 690             x, y = mtext.get_transform().transform_point(mtext.get_position())
    691             text_args.append("x=%fin" % (x * f))
    692             text_args.append("y=%fin" % (y * f))

/usr/local/lib/python3.5/dist-packages/matplotlib/transforms.py in transform_point(self, point)
   1421             msg = "The length of 'point' must be 'self.input_dims'"
   1422             raise ValueError(msg)
-> 1423         return self.transform(np.asarray([point]))[0]
   1424 
   1425     def transform_path(self, path):

/usr/local/lib/python3.5/dist-packages/matplotlib/transforms.py in transform(self, values)
   1330 
   1331         # Transform the values
-> 1332         res = self.transform_affine(self.transform_non_affine(values))
   1333 
   1334         # Convert the result back to the shape of the input values.

/usr/local/lib/python3.5/dist-packages/matplotlib/transforms.py in transform_affine(self, points)
   2367 
   2368     def transform_affine(self, points):
-> 2369         return self.get_affine().transform(points)
   2370     transform_affine.__doc__ = Transform.transform_affine.__doc__
   2371 

/usr/local/lib/python3.5/dist-packages/matplotlib/transforms.py in transform(self, values)
   1682 
   1683     def transform(self, values):
-> 1684         return self.transform_affine(values)
   1685     transform.__doc__ = Transform.transform.__doc__
   1686 

/usr/local/lib/python3.5/dist-packages/matplotlib/transforms.py in transform_affine(self, points)
   1766             tpoints = affine_transform(points.data, mtx)
   1767             return ma.MaskedArray(tpoints, mask=ma.getmask(points))
-> 1768         return affine_transform(points, mtx)
   1769 
   1770     def transform_point(self, point):

ValueError: object too deep for desired array

Expected outcome

Matplotlib version

  • Operating system: Ubuntu 16.04.3 LTS
  • Matplotlib version: 2.2.2
  • Matplotlib backend (print(matplotlib.get_backend())): module://ipykernel.pylab.backend_inline
  • Python version: 3.5.2
  • Jupyter version (if applicable):
    • jupyter (1.0.0)
      jupyter-client (5.1.0)
      jupyter-console (5.1.0)
      jupyter-core (4.3.0)
  • Other libraries: pandas 0.20.1

Everything installed using sudo pip3 (lazy sudo user...)

Thank you for support :)

@Phibedy

This comment has been minimized.

Copy link
Author

commented Mar 2, 2018

Works with matplotlib 2.1.2

@Phibedy Phibedy closed this Mar 2, 2018

@Phibedy Phibedy reopened this Apr 8, 2018

@Phibedy

This comment has been minimized.

Copy link
Author

commented Apr 8, 2018

After running some ubuntu updates it does not work again: Ubuntu 16.04.4 LTS
Nothing else changed. Even though I wrote that it works with matplotlib 2.1.2 I really wonder :/

mp.__version__numpy__, np.__version__
('1.7.1', '1.14.2')

Any ideas how to debug it?

@Phibedy Phibedy changed the title Can't save pgfs with text and dates Warning - save pgfs with text and dates Apr 8, 2018

@anntzer

This comment has been minimized.

Copy link
Contributor

commented Apr 25, 2019

works for me as of master.

@anntzer

This comment has been minimized.

Copy link
Contributor

commented Jul 14, 2019

Closing for lack of response since April, but feel free to ping for reopen if reproducible with a recent version of mpl.

@anntzer anntzer closed this Jul 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.