Skip to content

Commit

Permalink
added color rplot_data
Browse files Browse the repository at this point in the history
  • Loading branch information
robertocalandra committed Aug 26, 2017
1 parent 096f31e commit 870476f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
8 changes: 8 additions & 0 deletions examples/rplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
fig = rplot_data(data=x)
plt.show()

# Raw data
x = []
x.append(np.random.rand(100, 30))
x.append(np.random.rand(50, 20)+2)
# ---
fig = rplot_data(data=x, color=['red', 'green'])
plt.show()


# Mean vs median
NUM_SAMPLES = 500000 # Number curves within each distribution (e.g., the number of repetitions of each experiment)
Expand Down
27 changes: 19 additions & 8 deletions scipyplot/plot/gauss_1D.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
from scipyplot.plot.save2file import save2file

__author__ = 'Roberto Calandra'
__version__ = '0.5'
__version__ = '0.51'


def rplot_data(data, x=None, typeplot='mean+68+95+99', legend=None, xlabel=None, ylabel=None):
def rplot_data(data, x=None, typeplot='mean+68+95+99', legend=None, xlabel=None, ylabel=None, color=None):
"""
Plot curves from raw data (wrapper around rplot).
Given a matrix of data, this function automatically compute statistics (such as mean and var) and plot them.
Expand All @@ -32,6 +32,7 @@ def rplot_data(data, x=None, typeplot='mean+68+95+99', legend=None, xlabel=None,
:param legend: list of labels, one for each curve
:param xlabel: String. label for the x axis
:param ylabel: String. label for the y axis
:param color:
:return:
"""
if isinstance(data, np.ndarray):
Expand Down Expand Up @@ -59,7 +60,8 @@ def rplot_data(data, x=None, typeplot='mean+68+95+99', legend=None, xlabel=None,
# Is it a list then?
assert len(X) == len(Y)

fig = rplot(y=Y, x=X, uncertainty=V, distribution=distribution, xlabel=xlabel, ylabel=ylabel, legend=legend)
fig = rplot(y=Y, x=X, uncertainty=V, distribution=distribution, xlabel=xlabel, ylabel=ylabel, legend=legend,
color=color)

return fig

Expand Down Expand Up @@ -223,6 +225,10 @@ def rplot(y, uncertainty=None, x=None, color=None, alpha=0.60, distribution='68+

# Plot central curves
for i in range(n_curves):
if color is not None:
colorcurve = color[i]
else:
colorcurve = None
n_points = y[i].shape[0]
if x is None:
t = np.arange(n_points)
Expand All @@ -243,22 +249,27 @@ def rplot(y, uncertainty=None, x=None, color=None, alpha=0.60, distribution='68+

if (uncertainty is None) or (distribution is ''):
# Plot only curve
handle.append(plt.plot(t, y[i],
marker=next(marker), markersize=markersize, markevery=markerevery,
linestyle='-', linewidth=linewidth))
if colorcurve is None:
handle.append(plt.plot(t, y[i],
marker=next(marker), markersize=markersize, markevery=markerevery,
linestyle='-', linewidth=linewidth))
else:
handle.append(plt.plot(t, y[i],
marker=next(marker), markersize=markersize, markevery=markerevery,
linestyle='-', linewidth=linewidth, color=colorcurve))
else:
# Plot also distribution
assert isinstance(uncertainty[i], np.ndarray)
if np.squeeze(np.array(uncertainty[i])).ndim is 1:
handle.append(gauss_1D(y=y[i], x=t, variance=uncertainty[i], alpha=alpha,
marker=next(marker), markersize=markersize, markevery=markerevery,
linestyle='-', linewidth=linewidth,
distribution=distribution))
distribution=distribution, color=colorcurve))
else:
handle.append(distribution_1D(y=y[i], x=t, percentiles=uncertainty[i], alpha=alpha,
marker=next(marker), markersize=markersize, markevery=markerevery,
linestyle='-', linewidth=linewidth,
distribution=distribution))
distribution=distribution, color=colorcurve))

# Make figure nice
if xlabel is not None:
Expand Down

0 comments on commit 870476f

Please sign in to comment.