|
From: Stuart M. <Stu...@ob...> - 2014-03-05 01:21:44
|
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi,<br>
<br>
I'm seeing odd behavior with the relim() and autoscale_view() call
sequence with matplotlib 1.3.1. In some cases I am ending up with
axis ranges of [-0.05,0.05] instead of the actual data ranges. This
happens with scatter plots and sometimes with contour plots.<br>
<br>
The modified version of the scatter_demo2 below displays the
problem. I think this used to work for scatter plots with earlier
versions of matplotlib. Is this supposed to work or is there another
way to do it correctly (other than doing our own limit setting)?<br>
<br>
Thanks,<br>
Stuart<br>
<br>
"""<br>
Demo of scatter plot with varying marker colors and sizes.<br>
"""<br>
import numpy as np<br>
import matplotlib.pyplot as plt<br>
import matplotlib.cbook as cbook<br>
<br>
# Load a numpy record array from yahoo csv data with fields date,<br>
# open, close, volume, adj_close from the mpl-data/example
directory.<br>
# The record array stores python datetime.date as an object array in<br>
# the date column<br>
datafile = cbook.get_sample_data('goog.npy')<br>
price_data = np.load(datafile).view(np.recarray)<br>
price_data = price_data[-250:] # get the most recent 250 trading
days<br>
<br>
delta1 = np.diff(price_data.adj_close)/price_data.adj_close[:-1]<br>
<br>
# Marker size in units of points^2<br>
volume = (15 * price_data.volume[:-2] / price_data.volume[0])**2<br>
close = 0.003 * price_data.close[:-2] / 0.003 * price_data.open[:-2]<br>
<br>
fig, ax = plt.subplots()<br>
ax.scatter(delta1[:-1], delta1[1:], c=close, s=volume, alpha=0.5)<br>
<br>
# These cause ranges to be set incorrectly to [-0.055,0.055]
!!!!!!!!!!<br>
ax.relim()<br>
ax.autoscale_view( tight = True )<br>
<br>
ax.set_xlabel(r'$\Delta_i$', fontsize=20)<br>
ax.set_ylabel(r'$\Delta_{i+1}$', fontsize=20)<br>
ax.set_title('Volume and percent change')<br>
<br>
ax.grid(True)<br>
<br>
fig.tight_layout()<br>
<br>
plt.show()<font face="Verdana, Arial, Helvetica, sans-serif"
size="1"><br>
</font>
</body>
</html>
|