question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`ValueError` from the `matplotlib` backend

See original GitHub issue

I’m just trying to plot 3 genes but I’m getting a ValueError from the matplotlib backend

features = [
]
data = df_gff3.iloc[loc_target]
start = int(data["pos_start"])
end = int(data["pos_end"])
print(end - start)
features.append(GraphicFeature(start=start, end=end, strand={"+":+1, "-":-1}[data["sense"]], color="teal", label=data["locus_tag"]))
record = GraphicRecord(sequence_length=end - start, features=features)
record.plot(figure_width=100)


# ---------------------------------------------------------------------------
# ValueError                                Traceback (most recent call last)
# ~/anaconda/envs/µ_env/lib/python3.6/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)

# ~/anaconda/envs/µ_env/lib/python3.6/site-packages/IPython/core/pylabtools.py in <lambda>(fig)
#     242 
#     243     if 'png' in formats:
# --> 244         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
#     245     if 'retina' in formats or 'png2x' in formats:
#     246         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

# ~/anaconda/envs/µ_env/lib/python3.6/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
#     126 
#     127     bytes_io = BytesIO()
# --> 128     fig.canvas.print_figure(bytes_io, **kw)
#     129     data = bytes_io.getvalue()
#     130     if fmt == 'svg':

# ~/anaconda/envs/µ_env/lib/python3.6/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, **kwargs)
#    2073                     orientation=orientation,
#    2074                     bbox_inches_restore=_bbox_inches_restore,
# -> 2075                     **kwargs)
#    2076             finally:
#    2077                 if bbox_inches and restore_bbox:

# ~/anaconda/envs/µ_env/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)
#     508 
#     509         """
# --> 510         FigureCanvasAgg.draw(self)
#     511         renderer = self.get_renderer()
#     512 

# ~/anaconda/envs/µ_env/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py in draw(self)
#     394         Draw the figure using the renderer.
#     395         """
# --> 396         self.renderer = self.get_renderer(cleared=True)
#     397         # acquire a lock on the shared font cache
#     398         RendererAgg.lock.acquire()

# ~/anaconda/envs/µ_env/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py in get_renderer(self, cleared)
#     415 
#     416         if need_new_renderer:
# --> 417             self.renderer = RendererAgg(w, h, self.figure.dpi)
#     418             self._lastKey = key
#     419         elif cleared:

# ~/anaconda/envs/µ_env/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py in __init__(self, width, height, dpi)
#      85         self.width = width
#      86         self.height = height
# ---> 87         self._renderer = _RendererAgg(int(width), int(height), dpi)
#      88         self._filter_renderers = []
#      89 

# ValueError: Image size of 427363x153 pixels is too large. It must be less than 2^16 in each direction.
# <Figure size 7200x158.4 with 1 Axes>

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Zulkocommented, Jul 29, 2019

Great, happy I could be of some help! Let me know if you run into any other trouble.

0reactions
jolespincommented, Jul 29, 2019

Haha, yea a 2.5 meter figure is a little much for what I was trying to do. Thank you so much for responding! I was almost about to recreate the wheel and was very bummed out b/c your figures already look so good.

I ended up using this edit that you suggested

sequence_length = 4653851
features = list()
positions = list()
pad = 10
for k in range(-n_peripheral, n_peripheral+1):
    data = df_gff3.iloc[loc_target+k]
    start = int(data["pos_start"])
    end = int(data["pos_end"])
    strand = {"+":+1, "-":-1}[data["sense"]]
    label = data["locus_tag"]
    feature = GraphicFeature(start=start, end=end, strand=strand, label=label)
    features.append(feature)
    positions += [start, end]
record = GraphicRecord(sequence_length=sequence_length, features=features).crop((min(positions)-pad, max(positions)+pad))
record.plot(figure_width=10)
Read more comments on GitHub >

github_iconTop Results From Across the Web

I met an matplotlib backend error just after Spyder launched
I ran into a more serious trouble: I tried to change the backend in Tools\preference\IPython console\Graphic\backend, and then selected Tkinter, ...
Read more >
How to solve an error of "ValueError: Key backend ... - GitHub
I've tried to re-install Anaconda several times and update the lasted version of matplotlib but I can find the solution.
Read more >
Source code for matplotlib.pyplot
Switching to an interactive backend is possible only if no event loop for ... raise ValueError("The passed figure is not managed by pyplot")...
Read more >
Python matplotlib Gtk backend not working - NixOS Discourse
Hello community, I am trying to set up my Python scientific environment ... in require_version raise ValueError('Namespace %s not available' ...
Read more >
Pandas plotting backend in Python
The Plotly plotting backend for Pandas is not intended to be a drop-in replacement for the default; it does not implement all or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found