Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Add a common example to compare style sheets#6476
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Add a common example to compare style sheets#6476
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Here are some examples of the figure, respectively with the |
Note to myself: it may be clever to add x- and y-label for at least one of the subplots. |
The PEP8 tests are now fine. However, since my last commitfe0abf7 that only corrected PEP8 typos, |
Apparently I also corrected a typo when determining |
""" | ||
list_of_colors = plt.rcParams['axes.prop_cycle'].by_key()['color'] | ||
max_idx = min(nb_samples, len(list_of_colors)) | ||
for color in list_of_colors[0:max_idx]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think something like this would work (which granted exercises more than color, but that seems like a feature).
forsty,jinzip(plt.rcParams['axes.prop_cycle'],range(nb_samples)):ax.add_patch(Circle(prng.normal(scale=3,size=2),radius=1.0,**sty))
Cyclers
are iterables that yield dictionaries exactly for**
ing into functions like this.
Seehttp://matplotlib.org/cycler/
|
also 👍 on this! |
@tacaswell : thanks for the doc on However, in this specific example, I'd rather do something like forsty_dict,jinzip(plt.rcParams['axes.prop_cycle'],range(nb_samples)):ax.add_patch(Circle(prng.normal(scale=3,size=2),radius=1.0,color=sty_dict['color'])) rather than |
def plot_scatter(ax, prng, nb_samples=200): | ||
""" Scatter plot. | ||
NB: `plt.scatter` doesn't use default colors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I don't think this is true any more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Correct,#6291
@QuLogic : thank you for all the comments and remarks! I did the suggested modifications. @tacaswell : normally, From the plotting point of view, I added a 2nd cloud of points in the scatter subplot: (i) to convince myself that where the green cluster is a bit hard to distinguish from the blue one, while with this other style the two clusters appear much more clearly. |
The subplot spacing still needs to be adjusted. Don't know if that should be in the script, or elsewhere, though. |
@@ -25,8 +24,8 @@ def plot_colored_sinusoidal_lines(ax): | |||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Wouldn't “Plot sinusoidal lines with colors following the style color cycle.” be more correct?
A |
Anyway, I've just seen some typos + that the script is using |
@afvincent What is the status on this one? Looks like something that would be nice to land for 2.0 |
@WeatherGod : the script now uses @jenshnielsen : there is still one issue that I am struggling with. I would llike to use In [2]:%tb---------------------------------------------------------------------------ValueErrorTraceback (mostrecentcalllast)/home/adrien/matplotlib/lib/matplotlib/backends/backend_agg.pycindraw(self)462463try:-->464self.figure.draw(self.renderer)465finally:466RendererAgg.lock.release()/home/adrien/matplotlib/lib/matplotlib/artist.pycindraw_wrapper(artist,renderer,*args,**kwargs)66defdraw_wrapper(artist,renderer,*args,**kwargs):67withwith_rasterized(artist,renderer):--->68returndraw(artist,renderer,*args,**kwargs)6970draw_wrapper._supports_rasterization=True/home/adrien/matplotlib/lib/matplotlib/figure.pycindraw(self,renderer)12601261mimage._draw_list_compositing_images(->1262renderer,self,dsu,self.suppressComposite)12631264renderer.close_group('figure')/home/adrien/matplotlib/lib/matplotlib/image.pycin_draw_list_compositing_images(renderer,parent,dsu,suppress_composite)137ifnot_compositeornothas_images:138forzorder,aindsu:-->139a.draw(renderer)140else:141# Composite any adjacent images together/home/adrien/matplotlib/lib/matplotlib/artist.pycindraw_wrapper(artist,renderer,*args,**kwargs)66defdraw_wrapper(artist,renderer,*args,**kwargs):67withwith_rasterized(artist,renderer):--->68returndraw(artist,renderer,*args,**kwargs)6970draw_wrapper._supports_rasterization=True/home/adrien/matplotlib/lib/matplotlib/axes/_base.pycindraw(self,renderer,inframe)2377renderer.stop_rasterizing()2378->2379mimage._draw_list_compositing_images(renderer,self,dsu)23802381renderer.close_group('axes')/home/adrien/matplotlib/lib/matplotlib/image.pycin_draw_list_compositing_images(renderer,parent,dsu,suppress_composite)137ifnot_compositeornothas_images:138forzorder,aindsu:-->139a.draw(renderer)140else:141# Composite any adjacent images together/home/adrien/matplotlib/lib/matplotlib/artist.pycindraw_wrapper(artist,renderer,*args,**kwargs)66defdraw_wrapper(artist,renderer,*args,**kwargs):67withwith_rasterized(artist,renderer):--->68returndraw(artist,renderer,*args,**kwargs)6970draw_wrapper._supports_rasterization=True/home/adrien/matplotlib/lib/matplotlib/collections.pycindraw(self,renderer)819defdraw(self,renderer):820self.set_sizes(self._sizes,self.figure.dpi)-->821Collection.draw(self,renderer)822823/home/adrien/matplotlib/lib/matplotlib/artist.pycindraw_wrapper(artist,renderer,*args,**kwargs)66defdraw_wrapper(artist,renderer,*args,**kwargs):67withwith_rasterized(artist,renderer):--->68returndraw(artist,renderer,*args,**kwargs)6970draw_wrapper._supports_rasterization=True/home/adrien/matplotlib/lib/matplotlib/collections.pycindraw(self,renderer)312313ifdo_single_path_optimization:-->314gc.set_foreground(tuple(edgecolors[0]))315gc.set_linewidth(self._linewidths[0])316gc.set_linestyle(self._linestyles[0])/home/adrien/matplotlib/lib/matplotlib/backend_bases.pycinset_foreground(self,fg,isRGBA)1027self._rgb=fg1028else:->1029self._rgb=colors.to_rgba(fg)10301031defset_graylevel(self,frac):/home/adrien/matplotlib/lib/matplotlib/colors.pycinto_rgba(c,alpha)137rgba=_colors_full_map.cache[c,alpha]138except (KeyError,TypeError):# Not in cache, or unhashable.-->139rgba=_to_rgba_no_colorcycle(c,alpha)140try:141_colors_full_map.cache[c,alpha]=rgba/home/adrien/matplotlib/lib/matplotlib/colors.pycin_to_rgba_no_colorcycle(c,alpha)196c=c[:3]+ (alpha,)197ifany(elem<0orelem>1foreleminc):-->198raiseValueError("RGBA values should be within 0-1 range")199returnc200ValueError:RGBAvaluesshouldbewithin0-1range It is a bit weird as it seems to occur only with PS : there are many more styles now than when I wrote this script the first time. The number of figures generated will be rather big : should we worry about that? |
afvincent commentedSep 5, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
My last commit (610ce04) reverts some of my previous changes in the docstrings. I don't know why I was sure the docstrings were supposed to be written """Does something…""" rather than """Do something…""", but reading again PEP 257 and Numpy documentation guide style, I realized I had remembered them totally backwards… Sorry for the noise! |
story645 commentedSep 5, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I'm wondering if how it's currently laid out, it might end up being a little difficult for people to compare...What about laying it out in a table, as such
And yes, I kinda think you can safely reduce the number of plots if broad style changes are what you're going for. |
@story645 I have just experimented a bit with your suggestion about a tabular layout : one issue that arises is the figure-related rcParams (in particular the face color for style with dark background). I will try to make a draft with one figure per face color value today. |
Sorry, this PR had fallen below my radar… I switched to a single row of demo plots as@story645 suggested, and indeed it looks nice (though I have kept all the previous demo plots). Actually, I have decided to stick to one figure per style, instead of one figure per figure face color: it makes the code simpler to read, and some style share the same face color but differ on other figure parameters (so this approach was not totally consistent). Here are some examples showing how it currently looks like: Is it a problem if I try to rebase the branch of this PR? It seems like I started working on this before top and right ticks were set to not visible by default… Beside some auto ticks are a bit weird but they may have been enhanced since last May. @NelleV Is the script new docstring OK for you :)? |
FYI, I rebase the code of my branches all the time, so don't hesitate :) |
187ce10
tocea7f28
CompareAgree that like styles should be grouped together, but I think classic should always be on top. Also 😄 about the new layout. |
afvincent commentedOct 16, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Oops: the complete commit message for2af4445 should be "Fix default value of the named parameter in 'plot_figure'". As I am not sure how ugly it is to amend a pushed commit, I let it as it is for the moment: if it was not something to do, just tell me and I will look how to take care of it through git. Anyway, this commit is pretty minor: I just realized that the keyword argument default value was not so clever anymore, as the style context manager is now outside More importantly, with commitc2347d1, styles are now usedmore or less in alphabetical order: only I am still opened to remarks and suggestions, in case this example needs some additional polishing step. Edit: typo, |
Style sheets reference | ||
====================== | ||
This scripts demonstrates the different available style sheets on a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
There is a typo: scripts -> script
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Indeed: fixed in97224f6.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks!
I am not very good at reading CI failure reports but I think the Appveyor one is of the usual “502 gateway”-type, while the Travis one:
is unrelated to this PR and was fixed by#7304 . |
While I am more than happy to merge with an appveyor failure, I am less happy about the travis error. Do you mind rebasing? |
97224f6
to09e1f3a
Compareafvincent commentedOct 19, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@NelleV I've just rebased my branch. Let's see if Travis is still complaining. Edit: Travis seems happy now :). |
Add a common example to compare style sheets
Backported to v2.x via992b5ee. |
This new example aims at producing a reference to compare the different styles, like for example
colormaps_reference.py
does for the colormaps. A separate figure is plotted for each available style sheet, so this may result in a big number of figures.The different subplots give an idea of the chosen style in various situations. There are taken from other examples in the
style_sheets
section, some of them slightly adapted. The sample data are "randomly" produced with a constant seed passed to the pseudo-random number generator instance.