X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion examples/color/color_cycle_default.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
"""
====================================
Colors in the default property cycle
====================================

Display the colors from the default prop_cycle.
"""

import numpy as np
import matplotlib.pyplot as plt


prop_cycle = plt.rcParams['axes.prop_cycle']
colors = prop_cycle.by_key()['color']

Expand Down
16 changes: 11 additions & 5 deletions examples/color/color_cycle_demo.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
"""
Demo of custom property-cycle settings to control colors and such
for multi-line plots.
===================
Styling with cycler
===================

Demo of custom property-cycle settings to control colors and other style
properties for multi-line plots.

This example demonstrates two different APIs:

1. Setting the default rc-parameter specifying the property cycle.
1. Setting the default rc parameter specifying the property cycle.
This affects all subsequent axes (but not axes already created).
2. Setting the property cycle for a specific axes. This only
affects a single axes.
2. Setting the property cycle for a single pair of axes.
"""
from cycler import cycler
import numpy as np
import matplotlib.pyplot as plt


x = np.linspace(0, 2 * np.pi)
offsets = np.linspace(0, 2*np.pi, 4, endpoint=False)
# Create array with shifted-sine curve along each column
yy = np.transpose([np.sin(x + phi) for phi in offsets])

# 1. Setting prop cycle on default rc parameter
plt.rc('lines', linewidth=4)
plt.rc('axes', prop_cycle=(cycler('color', ['r', 'g', 'b', 'y']) +
cycler('linestyle', ['-', '--', ':', '-.'])))
fig, (ax0, ax1) = plt.subplots(nrows=2)
ax0.plot(yy)
ax0.set_title('Set default color cycle to rgby')

# 2. Define prop cycle for single set of axes
ax1.set_prop_cycle(cycler('color', ['c', 'm', 'y', 'k']) +
cycler('lw', [1, 2, 3, 4]))
ax1.plot(yy)
Expand Down
11 changes: 8 additions & 3 deletions examples/color/colormaps_reference.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""
==================
Colormap reference
==================

Reference for colormaps included with Matplotlib.

This reference example shows all colormaps included with Matplotlib. Note that
Expand Down Expand Up @@ -35,9 +39,9 @@
import numpy as np
import matplotlib.pyplot as plt


# Have colormaps separated into categories:
# http://matplotlib.org/examples/color/colormaps_reference.html

cmaps = [('Perceptually Uniform Sequential',
['viridis', 'inferno', 'plasma', 'magma']),
('Sequential', ['Blues', 'BuGn', 'BuPu',
Expand Down Expand Up @@ -65,7 +69,7 @@
gradient = np.vstack((gradient, gradient))


def plot_color_gradients(cmap_category, cmap_list):
def plot_color_gradients(cmap_category, cmap_list, nrows):
fig, axes = plt.subplots(nrows=nrows)
fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99)
axes[0].set_title(cmap_category + ' colormaps', fontsize=14)
Expand All @@ -81,7 +85,8 @@ def plot_color_gradients(cmap_category, cmap_list):
for ax in axes:
ax.set_axis_off()


for cmap_category, cmap_list in cmaps:
plot_color_gradients(cmap_category, cmap_list)
plot_color_gradients(cmap_category, cmap_list, nrows)

plt.show()
27 changes: 10 additions & 17 deletions examples/color/named_colors.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,37 @@
"""
Visualization of named colors.
========================
Visualizing named colors
========================

Simple plot example with the named colors and its visual representation.
"""
from __future__ import division

from __future__ import (absolute_import, division, print_function,
unicode_literals)

import six

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import colors as mcolors


colors = dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS)

# Sort by hue, saturation, value and name.
# Sort colors by hue, saturation, value and name.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't remove; two blank lines after imports.

by_hsv = sorted((tuple(mcolors.rgb_to_hsv(mcolors.to_rgba(color)[:3])), name)
for name, color in colors.items())

# Get the sorted color names.
sorted_names = [name for hsv, name in by_hsv]

n = len(sorted_names)
ncols = 4
nrows = int(np.ceil(1. * n / ncols))
nrows = n // ncols + 1

fig, ax = plt.subplots(figsize=(8, 5))

# Get height and width
X, Y = fig.get_dpi() * fig.get_size_inches()

# row height
h = Y / (nrows + 1)
# col width
w = X / ncols

for i, name in enumerate(sorted_names):
col = i % ncols
row = int(i / ncols)
row = i // ncols
y = Y - (row * h) - h

xi_line = w * (col + 0.05)
Expand All @@ -49,8 +42,8 @@
horizontalalignment='left',
verticalalignment='center')

ax.hlines(
y + h * 0.1, xi_line, xf_line, color=colors[name], linewidth=(h * 0.6))
ax.hlines(y + h * 0.1, xi_line, xf_line,
color=colors[name], linewidth=(h * 0.6))

ax.set_xlim(0, X)
ax.set_ylim(0, Y)
Expand Down
4 changes: 4 additions & 0 deletions examples/pie_and_polar_charts/pie_demo_features.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""
===============
Basic pie chart
===============

Demo of a basic pie chart plus a few additional features.

In addition to the basic pie chart, this demo shows a few optional features:
Expand Down
6 changes: 6 additions & 0 deletions examples/pie_and_polar_charts/polar_bar_demo.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
"""
=======================
Pie chart on polar axis
=======================

Demo of bar plot on a polar axis.
"""
import numpy as np
import matplotlib.pyplot as plt


# Fixing random state for reproducibility
np.random.seed(19680801)

# Compute pie slices
N = 20
theta = np.linspace(0.0, 2 * np.pi, N, endpoint=False)
radii = 10 * np.random.rand(N)
Expand Down
10 changes: 7 additions & 3 deletions examples/pie_and_polar_charts/polar_scatter_demo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""
==========================
Scatter plot on polar axis
==========================

Demo of scatter plot on a polar axis.

Size increases radially in this example and color increases with angle
Expand All @@ -7,18 +11,18 @@
import numpy as np
import matplotlib.pyplot as plt


# Fixing random state for reproducibility
np.random.seed(19680801)


# Compute areas and colors
N = 150
r = 2 * np.random.rand(N)
theta = 2 * np.pi * np.random.rand(N)
area = 200 * r**2
colors = theta

ax = plt.subplot(111, projection='polar')
c = ax.scatter(theta, r, c=colors, s=area, cmap=plt.cm.hsv)
c.set_alpha(0.75)
c = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75)

plt.show()
1 change: 0 additions & 1 deletion examples/style_sheets/plot_bmh.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
def plot_beta_hist(ax, a, b):
ax.hist(beta(a, b, size=10000), histtype="stepfilled",
bins=25, alpha=0.8, normed=True)
return ax


fig, ax = plt.subplots()
Expand Down
17 changes: 9 additions & 8 deletions examples/style_sheets/plot_fivethirtyeight.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@
from matplotlib import pyplot as plt
import numpy as np

plt.style.use('fivethirtyeight')

x = np.linspace(0, 10)

# Fixing random state for reproducibility
np.random.seed(19680801)

fig, ax = plt.subplots()

with plt.style.context('fivethirtyeight'):
ax.plot(x, np.sin(x) + x + np.random.randn(50))
ax.plot(x, np.sin(x) + 0.5 * x + np.random.randn(50))
ax.plot(x, np.sin(x) + 2 * x + np.random.randn(50))
ax.plot(x, np.sin(x) - 0.5 * x + np.random.randn(50))
ax.plot(x, np.sin(x) - 2 * x + np.random.randn(50))
ax.plot(x, np.sin(x) + np.random.randn(50))
ax.set_title("'fivethirtyeight' style sheet")
ax.plot(x, np.sin(x) + x + np.random.randn(50))
ax.plot(x, np.sin(x) + 0.5 * x + np.random.randn(50))
ax.plot(x, np.sin(x) + 2 * x + np.random.randn(50))
ax.plot(x, np.sin(x) - 0.5 * x + np.random.randn(50))
ax.plot(x, np.sin(x) - 2 * x + np.random.randn(50))
ax.plot(x, np.sin(x) + np.random.randn(50))
ax.set_title("'fivethirtyeight' style sheet")


plt.show()
X Tutup