Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Bug]: Setting axis to log scale produces font not found error #22281

Copy link
Copy link
Closed
@chinisan

Description

@chinisan
Issue body actions

Bug summary

I am using the example for a log bar chart, but I stumbled upon that error for my own plot.

When setting an axis to log scale, I get a font not found error.
Without that line everything works.

I tried it in a jupyter notebook, and a simple .py file and in both cases I get the same error.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np

data = ((3, 1000), (10, 3), (100, 30), (500, 800), (50, 1))

dim = len(data[0])
w = 0.75
dimw = w / dim

fig, ax = plt.subplots()
x = np.arange(len(data))
for i in range(len(data[0])):
    y = [d[i] for d in data]
    b = ax.bar(x + i * dimw, y, dimw, bottom=0.001)

# ax.set_xticks(x + dimw / 2, labels=map(str, x))
ax.set_yscale('log')

ax.set_xlabel('x')
ax.set_ylabel('y')

plt.show()

Actual outcome

findfont: Font family ['DejaVu Sans'] not found. Falling back to DejaVu Sans.


ValueError Traceback (most recent call last)
~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/IPython/core/formatters.py in call(self, obj)
339 pass
340 else:
--> 341 return printer(obj)
342 # Finally look for special method names
343 method = get_real_method(obj, self.print_method)

~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/IPython/core/pylabtools.py in (fig)
246
247 if 'png' in formats:
--> 248 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
249 if 'retina' in formats or 'png2x' in formats:
250 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
130 FigureCanvasBase(fig)
131
--> 132 fig.canvas.print_figure(bytes_io, **kw)
133 data = bytes_io.getvalue()
134 if fmt == 'svg':

~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
2191 else suppress())
2192 with ctx:
-> 2193 self.figure.draw(renderer)
2194
2195 bbox_inches = self.figure.get_tightbbox(

~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
39 renderer.start_filter()
40
---> 41 return draw(artist, renderer, *args, **kwargs)
42 finally:
43 if artist.get_agg_filter() is not None:

~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/matplotlib/figure.py in draw(self, renderer)
1861
1862 self.patch.draw(renderer)
-> 1863 mimage._draw_list_compositing_images(
1864 renderer, self, artists, self.suppressComposite)
1865

~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together

~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
39 renderer.start_filter()
40
---> 41 return draw(artist, renderer, *args, **kwargs)
42 finally:
43 if artist.get_agg_filter() is not None:

~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/matplotlib/cbook/deprecation.py in wrapper(*inner_args, **inner_kwargs)
409 else deprecation_addendum,
410 **kwargs)
--> 411 return func(*inner_args, **inner_kwargs)
412
413 return wrapper

~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)
2745 renderer.stop_rasterizing()
2746
-> 2747 mimage._draw_list_compositing_images(renderer, self, artists)
2748
2749 renderer.close_group('axes')

~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together

~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
39 renderer.start_filter()
40
---> 41 return draw(artist, renderer, *args, **kwargs)
42 finally:
43 if artist.get_agg_filter() is not None:

~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/matplotlib/axis.py in draw(self, renderer, *args, **kwargs)
1163
1164 ticks_to_draw = self._update_ticks()
-> 1165 ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
1166 renderer)
1167

~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/matplotlib/axis.py in _get_tick_bboxes(self, ticks, renderer)
1089 def _get_tick_bboxes(self, ticks, renderer):
1090 """Return lists of bboxes for ticks' label1's and label2's."""
-> 1091 return ([tick.label1.get_window_extent(renderer)
1092 for tick in ticks if tick.label1.get_visible()],
1093 [tick.label2.get_window_extent(renderer)

~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/matplotlib/axis.py in (.0)
1089 def _get_tick_bboxes(self, ticks, renderer):
1090 """Return lists of bboxes for ticks' label1's and label2's."""
-> 1091 return ([tick.label1.get_window_extent(renderer)
1092 for tick in ticks if tick.label1.get_visible()],
1093 [tick.label2.get_window_extent(renderer)

~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/matplotlib/text.py in get_window_extent(self, renderer, dpi)
900
901 with cbook._setattr_cm(self.figure, dpi=dpi):
--> 902 bbox, info, descent = self._get_layout(self._renderer)
903 x, y = self.get_unitless_position()
904 x, y = self.get_transform().transform((x, y))

~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/matplotlib/text.py in _get_layout(self, renderer)
293 clean_line, ismath = self._preprocess_math(line)
294 if clean_line:
--> 295 w, h, d = renderer.get_text_width_height_descent(
296 clean_line, self._fontproperties, ismath=ismath)
297 else:

~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py in get_text_width_height_descent(self, s, prop, ismath)
231 if ismath:
232 ox, oy, width, height, descent, fonts, used_characters =
--> 233 self.mathtext_parser.parse(s, self.dpi, prop)
234 return width, height, descent
235

~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/matplotlib/mathtext.py in parse(self, s, dpi, prop)
3330 # mathtext.fontset rcParams also affect the parse (e.g. by affecting
3331 # the glyph metrics).
-> 3332 return self._parse_cached(
3333 s, dpi, prop, rcParams['ps.useafm'], rcParams['mathtext.fontset'])
3334

~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/matplotlib/mathtext.py in _parse_cached(self, s, dpi, prop, ps_useafm, fontset)
3345 fontset_class = cbook._check_getitem(
3346 self._font_type_mapping, fontset=fontset)
-> 3347 font_output = fontset_class(prop, backend)
3348
3349 fontsize = prop.get_size_in_points()

~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/matplotlib/mathtext.py in init(self, *args, **kwargs)
907 })
908 for key, name in self._fontmap.items():
--> 909 fullpath = findfont(name)
910 self.fontmap[key] = fullpath
911 self.fontmap[name] = fullpath

~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/matplotlib/font_manager.py in findfont(self, prop, fontext, directory, fallback_to_default, rebuild_if_missing)
1309 "font.serif", "font.sans-serif", "font.cursive", "font.fantasy",
1310 "font.monospace"])
-> 1311 filename = self._findfont_cached(
1312 prop, fontext, directory, fallback_to_default, rebuild_if_missing,
1313 rc_params)

~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/matplotlib/font_manager.py in _findfont_cached(self, prop, fontext, directory, fallback_to_default, rebuild_if_missing, rc_params)
1358 default_prop = prop.copy()
1359 default_prop.set_family(self.defaultFamily[fontext])
-> 1360 return self.findfont(default_prop, fontext, directory,
1361 fallback_to_default=False)
1362 else:

~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/matplotlib/font_manager.py in findfont(self, prop, fontext, directory, fallback_to_default, rebuild_if_missing)
1309 "font.serif", "font.sans-serif", "font.cursive", "font.fantasy",
1310 "font.monospace"])
-> 1311 filename = self._findfont_cached(
1312 prop, fontext, directory, fallback_to_default, rebuild_if_missing,
1313 rc_params)

~/opt/anaconda3/envs/cilocharging/lib/python3.9/site-packages/matplotlib/font_manager.py in _findfont_cached(self, prop, fontext, directory, fallback_to_default, rebuild_if_missing, rc_params)
1361 fallback_to_default=False)
1362 else:
-> 1363 raise ValueError(f"Failed to find font {prop}, and fallback "
1364 f"to the default font was disabled")
1365 else:

ValueError: Failed to find font DejaVu Sans:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0, and fallback to the default font was disabled

Expected outcome

bar chart like here
https://matplotlib.org/stable/gallery/scales/log_bar.html#sphx-glr-gallery-scales-log-bar-py

Additional information

This was working on windows.
I get the same problem in within and outside of jupyter notebook.

Operating system

macOS

Matplotlib Version

3.3.4

Matplotlib Backend

module://ipykernel.pylab.backend_inline

Python version

3.9.2

Jupyter version

No response

Installation

conda

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.