Skip to content

Text wrapping & better handling of kwargs in pyplot #942

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

Merged
merged 1 commit into from
Jun 15, 2012

Conversation

pelson
Copy link
Member

@pelson pelson commented Jun 11, 2012

As mentioned in #928, I have some improvements to pyplot which required an improved workflow for generating the pyplot script in the first place. These are those changes.

Firstly, I have added text wrapping in the pyplot module such that no autogenerated line is longer than 80 characters.

Secondly, I have fixed a bug where keyword passing is miss-handled (keywords were previously being passed as positional arguments), which is best demonstrated by the following example:

import matplotlib.pyplot as plt
import matplotlib.axes as maxes
import matplotlib.projections as mproj


class MyAxes(maxes.Axes):
    name = 'myaxes'
    def imshow(self, *args, **kwargs):
        kwargs.setdefault('alpha', 0.5)
        maxes.Axes.imshow(self, *args, **kwargs)

mproj.register_projection(MyAxes)

plt.gca(projection='myaxes')
plt.imshow('my_img.png')

Resulting in the following error:

TypeError: imshow() got multiple values for keyword argument 'alpha'

@WeatherGod
Copy link
Member

Ooooh, I gotta test this one out. It might solve a problem for me in mplot3d.

@WeatherGod
Copy link
Member

Hmmm, it does not solve the problem I have for mplot3d's scatter() (I get an error message saying that multiple values for 'zs' is given for the invocation as plt.scatter(x, y, zs=z), and I get an error saying that multiple values for 'c' is given for the invocation as plt.scatter(x, y, z). Note that I don't expect the latter to work.

@pelson
Copy link
Member Author

pelson commented Jun 13, 2012

Are you sure? The following code works for me on this branch, but not for me on master:

import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

ax = plt.axes(projection='3d')
n = 3

xs = np.random.randint(23, 32, n)
ys = np.random.randint(0, 100, n)
zs = np.random.randint(0, 10, n)
plt.scatter(xs, ys, zs=zs)

plt.show()

@WeatherGod
Copy link
Member

Huh, must have used the wrong branch or maybe the pyplot.py file didn't rebuild properly? It now works from a clean install. Neat!

We probably should make sure that all tests pass and that the examples in the documentation didn't break.

@pelson
Copy link
Member Author

pelson commented Jun 14, 2012

We probably should make sure that all tests pass and that the examples in the documentation didn't break.

Should have said, I have done a test run and full documentation build before opening the PR.

Seems like there are no concerns so I will merge in ~18 hours (tomorrow morning for me).

pelson pushed a commit that referenced this pull request Jun 15, 2012
Text wrapping & better handling of kwargs in pyplot
@pelson pelson merged commit 70c2cbb into matplotlib:master Jun 15, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants