-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
pylab.plot markers aren't independent from lines (pylab: 1.9.2) #4338
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
Comments
Case 2 and 3 are the intended behaviour, if a linestlye is not specified, use the default (which by default is '-'). Can you point to where in the documentation leads you to expect that case 3 would not draw a line? The linestlye getting applied to the markers I don't think is the intended behaviour and is probably a bug. |
indeed, there is plot() and there is scatter(). Plot draws lines with As for the linestyle question, I can't reproduce it with a somewhat recent On Wed, Apr 15, 2015 at 10:14 AM, Thomas A Caswell <[email protected]
|
On 2015/04/15 4:46 AM, Benjamin Root wrote:
No. It has always been intended that there are three use cases for plot: If dashed linestyle is being applied to marker boundaries in plot, I Eric |
It may have always been intended that way, but that isn't how users see it. In any case, I can not reproduce the bug indicated by the OP, and I see no On Wed, Apr 15, 2015 at 2:26 PM, Eric Firing [email protected]
|
The bug -- that markers are picking up the linestyle -- may be backend-specific. What backend are you using? |
I am using TkAgg. On Wed, Apr 15, 2015 at 2:57 PM, Michael Droettboom <
|
On 2015/04/15 8:54 AM, Benjamin Root wrote:
Some users. Your perspective is new to me.
I wouldn't call non-default "exceptional". I don't want the plot-with-markers-only to be discouraged, or Being able to switch between line only and markers only in plot is an
But that's not a valid argument for saying scatter should be used when
That's the point: one doesn't want that, so if it occurs, it's a bug. |
I completely realize that it is some users. I make zero claim that all I should point out that similar discussions have occurred over in the On Wed, Apr 15, 2015 at 3:30 PM, Eric Firing [email protected]
|
@tacaswell the documentation says,
When "or" is applied here, I would interpret as plot-line-only or plot-markers-only. @WeatherGod @mdboom While typing this reply, I got a breakthrough. I think @mdboom is correct, because the result looks differently before and after being saved! And here is after saved (Now the markers' edge looks different from it in the last figure): Thank you guys for your attention! Though this may not be serious, I appreciate |
I have a history of encouraging users to use plot-with-out-a-line in any case where they wanted just markers and only to use scatter if they wanted to scale either the size or color of the markers as a function of a third (or fourth) dimension. attn @mdehoon this looks like a macosx specific issue. |
I would also point out that |
Thanks @tacaswell! I'll migrate to using ax.plot instead of DataFrame.plot:) |
I believe the bug is in the Line2D class, specifically the draw() method, in this section: funcname = self._lineStyles.get(self._linestyle, '_draw_nothing')
if funcname != '_draw_nothing':
tpath, affine = transf_path.get_transformed_path_and_affine()
if len(tpath.vertices):
self._lineFunc = getattr(self, funcname)
funcname = self.drawStyles.get(self._drawstyle, '_draw_lines')
drawFunc = getattr(self, funcname)
drawFunc(renderer, gc, tpath, affine.frozen()) # (A)
if self._marker: # (B)
gc = renderer.new_gc()
self._set_gc_clip(gc)
rgbaFace = self._get_rgba_face() At line (A), we call drawFunc and give it the graphics context. drawFunc tells the graphics context to draw lines as dashed lines. At line (B), we use the same graphics context to draw the marker. So it also gets drawn with dashed lines. The bug can be fixed by saving and restoring the graphics context around line (A): gc = renderer.new_gc()
drawFunc(renderer, gc, tpath, affine.frozen()) # (A)
gc.restore() |
In the code block in line (B) there is a call to It looks like the OSX backend returns the same context (not a new one) when If this is related the inherent limitations of the osx backend (that it can't have more than one gc?) we need to have a discussion about how much we want to complicate/restrict/rewrite the rest of the library to deal with it. I suspect that we could work around this by having the OSX backend return proxy objects and keep a weakref to them (so it can tell when the clients of the gc have gone out of scope) and maintain a stack of states internally. It might be simpler to use proxy objects which just keep a copy of the state the GC should have, a ref to the osx gc, and updates the osx gc dynamically every time it is used. |
We had this discussion several years ago. new_gc is a bit of a misnomer; it does not guarantee to create a new graphics context. In fact, on Mac OS X it never returns a new graphics context, as the OS has no way of creating a new graphics context from scratch. This is not a problem as long as the calling code does not assume that the graphics context is actually new. Matplotlib abides by this rule whenever new_gc is used. I think that there are very few cases in matplotlib where this rule is not followed; if there were, we'd be running into bugs all the time. |
Maybe it is time to consider rewriting graphics contexts as context On Thu, Apr 16, 2015 at 9:23 AM, mdehoon [email protected] wrote:
|
Btw it seems to me that we can get rid of the call to new_gc in the line following (B), and the corresponding gc.restore() further down. |
I am seeing the same bug with gtkcairo on Linux. Anyway, I am a bit confused about the draw() method of Line2D. Modifying the graphics context in lines 692-708 is only relevant if funcname != '_draw_nothing', as tested in line 711. Then wouldn't it make sense to perform this test first, and then modify the graphics context? |
@enfeizhan Can you try pull request #4348 to confirm it fixes this bug, and that at doesn't introduce new bugs? It would be great if you could check both with the Mac OS X native backend and with the Tkagg backend. |
FIX : Reorder the code in the draw() method of Line2D fixes #4338
Once again the Mac OS X native backend is absolved of all blame :-). |
pylab.plot
is supposed to draw lines and/or markers but it turns out markers aren't independent from lines. Here is an example:There are of-course ways to get around these problems, but wondering maybe this is a bug unexpected by maintainers.
The text was updated successfully, but these errors were encountered: