matplotlib / matplotlib/matplotlib

Support partial usetex in ps output

Open
#7,741 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backend: ps keep New feature topic: text/usetex
Dominant language
Python
Stars
23.2k
Forks
8.5k
Avg merge
1d 6h
Merged PRs (30d)
66

Description

I am trying to save some figures I made as .ps or .eps but I am getting an error. I narrowed the error down to the fact that I am using Latex for some of the text in my figure but using rc.params['text.usetex'] = False. Here is some code that reproduces the bug:

import matplotlib
import matplotlib.pyplot as plt
fig = plt.figure()
plt.text(0.5, 0.5, 'Here is some text, $math mode$', ha='center', va='center', usetex=True)
fig.savefig('test.ps')

The error you get is AttributeError: 'RendererPS' object has no attribute 'textcnt'

When looking at this code in in the RendererPS class the textcnt attribute is only added when rc.params['text.usetex'] = True. However I am just using Latex for specific text objects with the option usetex=True. Is there a way to save these figures as .ps or .eps?

I am using Matplotlib 1.5.1 installed via conda on Windows with python 2.7. I also tested it with Matplotlib 2.0.0b4 which also produced the same error, however I would prefer a solution for 1.5.1 if possible.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with lib/matplotlib/backends/backend_ps.py and the RendererPS handling of textcnt, then run the issue's minimal Python example that saves a figure as test.ps. Confirm the behavior for text objects using usetex=True while the global setting is false; done means PS and EPS output save without the reported AttributeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
latex, matplotlib, python
Domain
backend, data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.