| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
This is in the latest master as of 1184f78 |
Sorry, something went wrong.
|
Do you have anything customized in your matplotlibrc? Which backend is this? |
Sorry, something went wrong.
|
I suspect you're on the MacOsx backend. First, try Agg instead. Second, try passing "snap=True" or "snap=False" to both of them. I suspect one or the other method is ignoring that flag. |
Sorry, something went wrong.
|
I tried using the Agg backend (I guess it was using MacOS X) but that doesn't help. Setting snap=False in plot does help, though I don't quite get what you do. Setting snap in LineCollection has no effect. |
Sorry, something went wrong.
Sorry, something went wrong.
|
Also, I made sure to remove my .matplotlib directory first to ensure no custom configuration. |
Sorry, something went wrong.
|
Ok -- are you sure this is the Agg backend? What does import matplotlib matplotlib.get_backend() give? |
Sorry, something went wrong.
|
The full script is: import matplotlib
matplotlib.use('Agg')
print(matplotlib.get_backend())
from matplotlib import pyplot as plt
from matplotlib.collections import LineCollection
x1, x2, y1, y2 = -6.87194525904,-6.87194525904,0.0446252911239,0.0478759487178
fig = plt.figure(figsize=(10,8))
ax = fig.add_subplot(1,1,1)
lc = LineCollection([([[x1, y1], [x2, y2]])], color='green')
ax.add_collection(lc)
ax.plot([x1, x2], [y1, y2], color='red')
fig.savefig('offset.png')
and the output is: $ python bug.py agg |
Sorry, something went wrong.
|
I was finally able to reproduce this -- I had forgotten I had a custom dpi set for some other testing. I think the attached resolves the (long standing) issue. |
Sorry, something went wrong.
|
Works perfectly - thanks!! |
Sorry, something went wrong.
Offset between plot and LineCollection
|
It would seem that this merge has had an impact on the behaviour of pcolor that becomes evident when a comparison between pcolor and pcolormesh is carried out. This can be seen in the image below, where 10 random values are plotted onto the same axes, using pcolor for the left column and pcolormesh for the right (and generated using the version of matplotlib as at the point where this commit was merged): But setting snap=False on the pcolor call solves this: However this problem does not show up in an earlier version of matplotlib (namely v1.2.1). Here the pcolor call has no snap keyword set yet the problem does not appear: The code used to generate these three images is as below (but note that snap=False is added to the pcolor call for the second image): import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import numpy.random as rnd
MPL_VERSION = matplotlib.__version__
nx, ny = 1, 10
x0, x1 = [0, 1], [1, 2]
y = np.arange(ny+1)
X0, Y = np.meshgrid(x0, y)
X1, Y = np.meshgrid(x1, y)
rnd.seed(5)
z = rnd.randint(20, size=(ny, 1)).astype(np.float32)
fig = plt.figure(dpi=45)
pcr_ax = plt.subplot(111)
plt.pcolor(X0, Y, z)
plt.pcolormesh(X1, Y, z)
pcr_ax.grid(True)
pcr_ax.set_xlim([0, nx+1])
pcr_ax.set_ylim([0, ny])
plt.title('pcolor - pcolormesh (using MPL v{})'.format(MPL_VERSION))
plt.savefig('comparison_mpl_v{}_snap.png'.format(MPL_VERSION),
dpi=45)
plt.show() |
Sorry, something went wrong.
|
@dkillick: Is your proposal that we should be setting snap=False as default to pcolor then? |
Sorry, something went wrong.
|
@pelson the above was designed just to highlight the problem, not to also recommend a solution. |
Sorry, something went wrong.
|
#2726 turns of snap in pcolor, and it does revert your example to the old behavior. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
There is a 1 pixel offset between the result of ax.plot and a LineCollection with the same values:
from matplotlib import pyplot as plt from matplotlib.collections import LineCollection x1, x2, y1, y2 = -6.87194525904,-6.87194525904,0.0446252911239,0.0478759487178 fig = plt.figure(figsize=(10,8)) ax = fig.add_subplot(1,1,1) lc = LineCollection([([[x1, y1], [x2, y2]])], color='green') ax.add_collection(lc) ax.plot([x1, x2], [y1, y2], color='red') fig.savefig('offset.png')gives:
If you zoom in, you'll see:
I think there is a 1 pixel offset in the two lines.
@mdboom, I'm mentioning you here since in my opinion this is bad enough to be potentially considered for a fix that should be included in 1.3.0.