[DOC] New figure for the gallery (showcase section) #7072

Merged
merged 9 commits into from Sep 11, 2016

Conversation

Projects
None yet
8 participants
Contributor

rougier commented Sep 9, 2016 edited

This is a figure for the showcase section. It shows the different elements composing a figure.

anatomy

@rougier rougier Removed link to repository
9acf1dd

mdboom added the needs_review label Sep 9, 2016

@rougier rougier Removed figure saving
a77e995

rougier changed the title from New figure for the gallery (showcase section) to [DOC] New figure for the gallery (showcase section) Sep 9, 2016

@NelleV NelleV and 2 others commented on an outdated diff Sep 9, 2016

examples/showcase/anatomy.py
@@ -0,0 +1,143 @@
+# This figure shows the name of several matplotlib elements composing a figure
+
+import numpy as np
+import matplotlib.pyplot as plt
+from matplotlib.patches import Circle
+from matplotlib.ticker import MultipleLocator, FuncFormatter
+
+np.random.seed(123)
+
+X = np.linspace(0.5, 3.5, 100)
+Y1 = 3+np.cos(X)
+Y2 = 1+np.cos(1+X/0.75)/2
+Y3 = np.random.uniform(Y1, Y2, len(X))
+
+plt.figure(figsize=(8, 8), facecolor="w")
@NelleV

NelleV Sep 9, 2016

Contributor

The two lines can be replaced by the following (which I find slightly more elegant):

fig, ax = plt.subplots(figsize=(8, 8), facecolor="w", subplot_kw={"aspect": 1})

@rougier

rougier Sep 9, 2016

Contributor

I'm not too fond of this syntax, I find it more confusing.

@jenshnielsen

jenshnielsen Sep 9, 2016

Owner

I think both ways are fine, But in the current I would replace the "matlab like" shorthand syntax

ax = plt.subplot(111, aspect=1)

with the more explicit version

ax = plt.subplot(1, 1, 1, aspect=1)

http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.subplot

Owner

jenshnielsen commented Sep 9, 2016

Really cool and useful plot. We should perhaps find a way to integrate it into the prose docs too

@tacaswell tacaswell commented on an outdated diff Sep 9, 2016

examples/showcase/anatomy.py
+
+# Scatter plot
+circle(3.20, 1.75)
+text(3.20, 1.55, "Markers\n(scatter plot)")
+
+# Grid
+circle(3.00, 3.00)
+text(3.00, 2.80, "Grid")
+
+# Legend
+circle(3.70, 3.75)
+text(3.70, 3.55, "Legend")
+
+# Axis
+circle(0.5, 0.5)
+text(0.5, 0.3, "Axis")
@tacaswell

tacaswell Sep 9, 2016

Owner

I think this should be 'Axes`

@tacaswell tacaswell commented on an outdated diff Sep 9, 2016

examples/showcase/anatomy.py
+
+# Grid
+circle(3.00, 3.00)
+text(3.00, 2.80, "Grid")
+
+# Legend
+circle(3.70, 3.75)
+text(3.70, 3.55, "Legend")
+
+# Axis
+circle(0.5, 0.5)
+text(0.5, 0.3, "Axis")
+
+# Plot
+circle(-0.3, 0.65)
+text(-0.3, 0.45, "Plot")
@tacaswell

tacaswell Sep 9, 2016

Owner

This should be 'Figure'

rougier added some commits Sep 9, 2016

@rougier rougier Fixed pylab-like syntax
2b8e33d
@rougier rougier Plot -> Figure
0a0b3e6
@rougier rougier Replaced old figure part with the new one from the gallery (showcase …
…section)
f6c9ac2
Contributor

rougier commented Sep 9, 2016

I've added a commit to change the figure in the FAQ. I canot yet compile the documentation to check the result though.

@rougier rougier Axis -> Axes
f2ef761
Owner

tacaswell commented Sep 9, 2016

@rougier What is still blocking you on the docs?

Contributor

rougier commented Sep 9, 2016

Oh only local problems, mostly because matplotlib is already installed from what I've understood.

Contributor

NelleV commented Sep 9, 2016

I can help with that if you come to see me.

On 9 September 2016 at 05:57, Nicolas P. Rougier notifications@github.com
wrote:

I've added a commit to change the figure in the FAQ. I canot yet compile
the documentation to check the result though.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#7072 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AALR3kIUyWVGagbhEXSnJegIE62UVWAEks5qoVe0gaJpZM4J46gH
.

@Kojoley Kojoley and 1 other commented on an outdated diff Sep 9, 2016

examples/showcase/anatomy.py
+plt.xlabel("X axis label")
+plt.ylabel("Y axis label")
+
+plt.legend(frameon=False)
+
+
+def circle(x, y, radius=0.15):
+ center = x, y
+ circle = Circle(center, radius, clip_on=False, zorder=10,
+ edgecolor='white', facecolor='none', linewidth=5.0)
+ plt.axes().add_artist(circle)
+ circle = Circle(center, radius, clip_on=False, zorder=20,
+ edgecolor='none', facecolor='black', alpha=.025)
+ plt.axes().add_artist(circle)
+ circle = Circle(center, radius, clip_on=False, zorder=30,
+ edgecolor='black', facecolor='none', linewidth=1.0)
@Kojoley

Kojoley Sep 9, 2016

Member

I think all of this could be simplified to one Circle call with help of PathEffects.withStroke http://matplotlib.org/examples/pylab_examples/patheffect_demo.html

@rougier

rougier Sep 9, 2016

Contributor

Not totally because of the transparency of the background (while the white outline is opaque)

@Kojoley

Kojoley Sep 9, 2016

Member

Try this, very close to what you have

def circle(x, y, radius=0.15):
    from matplotlib.patheffects import withStroke
    circle = Circle((x, y), radius, clip_on=False, zorder=10, linewidth=1,
                    edgecolor='black', facecolor=(0, 0, 0, .0125),
                    path_effects=[withStroke(linewidth=5, foreground='w')])
    plt.axes().add_artist(circle)
Owner

efiring commented Sep 9, 2016

This might further the misconception that markers must be made using scatter rather then plot. Would it be too cluttered it you were to illustrate the scatter plot using markers with varying size, and possibly color, and then show uniform markers in one of the two lines?

Member

QuLogic commented Sep 9, 2016

Have you tried building this figure with the 2.x branch? There are many small tweaks that may have been necessary before, but likely aren't now, e.g., there's no reason to turn off the frame legend now.

Also, the Figure and Axes annotations are a bit vague.

Member

Kojoley commented Sep 9, 2016

@rougier I have opened rougier#2 with circle creation simplification and OO modification.

Contributor

rougier commented Sep 9, 2016

@Kojoley Thanks, didn't know color arguments accept RGBA format. Your code much simpler now.

Contributor

rougier commented Sep 9, 2016

@efiring What would be the use case for scatter plot then ? It's seem reasonable to use scatter to plot a bunch of markers, no?

@rougier rougier Merge pull request #2 from Kojoley/suggestion-pr7072
Suggestions for #7072
2c29fd1
Contributor

NelleV commented Sep 9, 2016

@efiring @rougier We've had this problem with plot vs scatter since a very very long time. I think that the fact we are having still this problem shows an interface and naming problem (ie, a bug). How complicated it would it be to fix scatter so that it behaves like plot when no size or color argument are provided?

Contributor

NelleV commented Sep 9, 2016

@rougier the scatter plots is "supposed" to be used when displaying markers of different size or color (or both). It recomputes a bunch of elements for each marker you draw, while plot doesn't. It renders scatter plot quite inefficient both time wise and memory wise when used on large datasets.
There is absolutely no way a user would know this unless he/she had a look at the implementation.

Owner

efiring commented Sep 9, 2016

@NelleV Rather than modify scatter to return completely different artists (Line2D versus PatchCollection) depending on its arguments, I think the problem is addressed better via documentation and examples. Using scatter when plot would suffice is inefficient for very large data sets, as you note, but otherwise not harmful.

Owner

efiring commented Sep 9, 2016

@NelleV Note also that the argument lists for plot and scatter are very different, corresponding to the major differences between the artists they return.

@rougier rougier added a commit to rougier/figure-anatomy that referenced this pull request Sep 10, 2016

@rougier rougier Updated with @Kolojey changes (see matplotlib/matplotlib#7072) 4688541
Contributor

rougier commented Sep 11, 2016

Is it ready to merge or does it need more modifications ?

@tacaswell tacaswell merged commit 440adff into matplotlib:master Sep 11, 2016

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage decreased (-0.002%) to 70.36%
Details

tacaswell removed the needs_review label Sep 11, 2016

@tacaswell tacaswell added a commit that referenced this pull request Sep 11, 2016

@tacaswell tacaswell Merge pull request #7072 from rougier/showcase
DOC: Replace anatomy of a plot figure
ca51e8d
Owner

tacaswell commented Sep 11, 2016

backported to v2.x as ca51e8d

Member

QuLogic commented Sep 14, 2016

So we're keeping this with the ticks the wrong way?

Member

QuLogic commented Sep 14, 2016

Also, in v2.x, the markers are invisible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment