|
205 | 205 | import numpy as np |
206 | 206 | import pandas as pd |
207 | 207 | plot.rc['title.loc'] = 'uc' |
208 | | -plot.rc['axes.ymargin'] = plot.rc['axes.xmargin'] = 0.05 |
209 | 208 | state = np.random.RandomState(51423) |
210 | 209 | data = ( |
211 | 210 | state.rand(20, 8).cumsum(axis=0).cumsum(axis=1)[:, ::-1] |
|
258 | 257 | # `~proplot.axes.cycle_changer`, and `~proplot.axes.standardize_1d`. |
259 | 258 | # You can now *group* or *stack* columns of data by passing 2D arrays to |
260 | 259 | # `~matplotlib.axes.Axes.bar` or `~matplotlib.axes.Axes.barh`, just like in |
261 | | -# `pandas`. Also, `~matplotlib.axes.Axes.bar` and `~matplotlib.axes.Axes.barh` |
262 | | -# now employ "default" *x* coordinates if you failed to provide them |
263 | | -# explicitly, just like `~matplotlib.axes.Axes.plot`. |
| 260 | +# `pandas`, or use different colors for negative and positive bars by |
| 261 | +# passing ``negpos=True``. Also, `~matplotlib.axes.Axes.bar` and |
| 262 | +# `~matplotlib.axes.Axes.barh` now employ "default" *x* coordinates if you |
| 263 | +# failed to provide them explicitly. |
264 | 264 | # |
265 | 265 | # To make filled "area" plots, use the new `~proplot.axes.Axes.area` and |
266 | 266 | # `~proplot.axes.Axes.areax` methods. These are alises for |
|
270 | 270 | # `~proplot.axes.fill_betweenx_wrapper`. You can now *stack* or *overlay* |
271 | 271 | # columns of data by passing 2D arrays to `~proplot.axes.Axes.area` and |
272 | 272 | # `~proplot.axes.Axes.areax`, just like in `pandas`. You can also now draw |
273 | | -# area plots that *change color* when the fill boundaries cross each other by |
| 273 | +# area plots that change color when the fill boundaries cross each other by |
274 | 274 | # passing ``negpos=True`` to `~matplotlib.axes.Axes.fill_between`. The most |
275 | 275 | # common use case for this is highlighting negative and positive areas with |
276 | 276 | # different colors, as shown below. |
|
313 | 313 | # %% |
314 | 314 | import proplot as plot |
315 | 315 | import numpy as np |
316 | | -plot.rc.margin = 0 |
317 | | -fig, axs = plot.subplots(array=[[1, 2], [3, 3]], hratios=(1, 0.8), share=0) |
318 | | -axs.format(xlabel='xlabel', ylabel='ylabel', suptitle='Area plot demo') |
| 316 | +fig, axs = plot.subplots(array=[[1, 2], [3, 3]], hratios=(1, 1.5), share=0) |
| 317 | +axs.format(grid=False, xlabel='xlabel', ylabel='ylabel', suptitle='Area plot demo') |
319 | 318 | state = np.random.RandomState(51423) |
320 | 319 | data = state.rand(5, 3).cumsum(axis=0) |
321 | 320 | cycle = ('gray3', 'gray5', 'gray7') |
322 | 321 |
|
323 | | -# Overlaid and stacked area patches |
| 322 | +# Overlaid area patches |
324 | 323 | ax = axs[0] |
325 | 324 | ax.area( |
326 | | - np.arange(5), data, data + state.rand(5)[:, None], cycle=cycle, alpha=0.5, |
| 325 | + np.arange(5), data, data + state.rand(5)[:, None], cycle=cycle, alpha=0.7, |
327 | 326 | legend='uc', legend_kw={'center': True, 'ncols': 2, 'labels': ['z', 'y', 'qqqq']}, |
328 | 327 | ) |
329 | 328 | ax.format(title='Fill between columns') |
| 329 | + |
| 330 | +# Stacked area patches |
330 | 331 | ax = axs[1] |
331 | 332 | ax.area( |
332 | 333 | np.arange(5), data, stacked=True, cycle=cycle, alpha=0.8, |
333 | 334 | legend='ul', legend_kw={'center': True, 'ncols': 2, 'labels': ['z', 'y', 'qqqq']}, |
334 | 335 | ) |
335 | 336 | ax.format(title='Stack between columns') |
336 | 337 |
|
337 | | -# Positive and negative color area patches |
| 338 | +# Positive and negative color bars and area patches |
338 | 339 | ax = axs[2] |
339 | | -data = 5 * (state.rand(20) - 0.5) |
340 | | -ax.area(data, negpos=True, negcolor='blue7', poscolor='red7') |
341 | | -ax.format(title='Positive and negative colors', xlabel='xlabel', ylabel='ylabel') |
342 | | -axs.format(grid=False) |
| 340 | +data = 4 * (state.rand(20) - 0.5) |
| 341 | +ax.bar(data, bottom=-2, width=1, edgecolor='none', negpos=True) |
| 342 | +ax.area(data + 2, y2=2, negpos=True) |
| 343 | +for offset in (-2, 2): |
| 344 | + ax.axhline(offset, color='k', linewidth=1, linestyle='--') |
| 345 | +ax.format( |
| 346 | + xmargin=0, xlabel='xlabel', ylabel='ylabel', |
| 347 | + title='Positive and negative colors demo', titleweight='bold', |
| 348 | +) |
343 | 349 | plot.rc.reset() |
344 | 350 |
|
345 | 351 |
|
|
369 | 375 | data, |
370 | 376 | columns=pd.Index(['a', 'b', 'c', 'd', 'e'], name='xlabel') |
371 | 377 | ) |
372 | | -axs.format( |
373 | | - ymargin=0.1, xmargin=0.1, grid=False, |
374 | | - suptitle='Boxes and violins demo' |
375 | | -) |
| 378 | +axs.format(grid=False, suptitle='Boxes and violins demo') |
376 | 379 |
|
377 | 380 | # Box plots |
378 | 381 | ax = axs[0] |
|
428 | 431 | x, y, c, cmap=cmap, lw=7, interp=5, capstyle='round', joinstyle='round' |
429 | 432 | ) |
430 | 433 | ax.format(xlabel='xlabel', ylabel='ylabel', title='Line with smooth gradations') |
431 | | -ax.format(xmargin=0.05, ymargin=0.05) |
432 | 434 | ax.colorbar(m, loc='b', label='parametric coordinate', locator=5) |
433 | 435 |
|
434 | 436 | # Parametric line with stepped gradations |
|
0 commit comments