GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — twinx and plot_date · Issue #162 · matplotlib/matplotlib Closed Labels Milestone DescriptionOriginal report at SourceForge, opened Tue Aug 17 02:13:52 2010 This is my first bug submission; Please ask if more information is needed. I'm attempting to plot two data sets on a single figure with a common x axis but separate y axes. I want the first set to correspond to the right y-axis. My strategy is to add a set of axes to the figure, then create a second set of axes using twinx(), then use plot_date() to add data to the second set of axes. It appears that there is some problem in the order in which things are done that causes this to fail when the figure is drawn. I think the problem may have something to do with the default axis limits being (0.0, 1.0). These limits cannot be converted to dates since the range for dates is >= 1.0. Here is a simplified example of code that will fail: import matplotlib.pyplot as plt t = datetime.datetime.now().date() tarr = matplotlib.dates.date2num([t + datetime.timedelta(days=i) for i in varr]) This will failfig = plt.figure() ax2.plot_date(tarr, varr) fig.canvas.draw() SourceForge CommentsOn Fri Oct 22 10:55:06 2010, leejjoon wrote:This has been a known problem but not fixed yet. There could be a few other workarounds. One is not to use autoscale_view. ax1 = fig.add_subplot(1,1,1) ax2.plot_date(tarr, left_varr) ax2.set_xlim(min(tarr), max(tarr)) or add same data to the other axes but makes it invisible. ax2.plot_date(tarr, left_varr) I think one way to solve this issue is to check if axes have any artist (has_data method), and include only those axes with child artists during the autoscale_view. However, I'll let others review it. On Tue Aug 17 02:18:10 2010, pzakielarz wrote:Oops, I hit the add button too soon. Continuing on: The resulting traceback is: Traceback (most recent call last): I've come up with a work around that somewhat mimics twinx() and allows the rest of my code to work properly. ax1 = fig.add_subplot(1,1,1) ax1.plot_date(tarr, right_varr) ax1.yaxis.tick_right() fig.canvas.draw() ax2 = ax1.figure.add_axes(ax1.get_position(True), sharex=ax1, frameon=False) ax2.plot_date(tarr, left_varr) fig.canvas.draw() This workaround sets up my axes as desired and allows the rest of my code to function as intended. Activity
MetadataMetadataAssigneesLabelsTypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |