SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Phil E. <pj...@ha...> - 2004年03月04日 00:30:31
Attachments: testBug.jpg
Hello John,
 I have run into the following minor matplotlib bug. Using the sample 
code below, the y axis label and tick marks in the second subplot seem 
not to be in the right places. Also on that second subplot, the first 
legend is missing when the window is initially drawn, but gets redrawn 
correctly if I use the x axis interactive scrolling buttons.
 Attached to this note is a snapshot of the figure window as initially 
drawn showing the bugs. (I don't know whether the mailing list deals 
with attachments correctly, so I'm mailing you a copy directly.)
 The installation here is matplotlib version 0.50 running on a Redhat 
9 linux box:
[pje@amon site-packages]$ uname -a
Linux amon 2.4.20-6smp #1 SMP Thu Feb 27 09:59:40 EST 2003 i686 i686 
i386 GNU/Linux
-----------------------------------------------------------------------
Code:
from matplotlib.matlab import *
figure(1)
subplot(211)
plot(rand(50),'r')
plot(rand(30),'k')
plot(rand(80),'g')
plot(rand(70),'b')
plot(rand(60),'m')
plot(5 * array([1,1]), get(gca(),'ylim'), 'b')
plot(15 * array([1,1]), get(gca(),'ylim'), 'b')
axis([0,100,-2,2])
ylabel('Test me')
title('Test me')
legend(['TX Min', 'RX min', 'Pulse 1', 'Pulse 2', 'P1-P2'])
subplot(212)
plot(rand(50),'r')
plot(rand(30),'k')
plot(rand(80),'g')
plot(rand(70),'b')
plot(rand(60),'m')
plot(5 * array([1,1]), get(gca(),'ylim'), 'b')
plot(15 * array([1,1]), get(gca(),'ylim'), 'b')
axis([0,100,-2,2])
ylabel('Test me')
title('Test me')
legend(['TX Min', 'RX min', 'Pulse 1', 'Pulse 2', 'P1-P2'])
show()
--
----
Phil Erickson email: pj...@ha...
Atmospheric Sciences Group WWW: http://www.haystack.mit.edu
MIT Haystack Observatory voice: 781 981 5769
Westford, MA 01886 USA fax: 781 981 5766
Public key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x54878872
From: John H. <jdh...@ac...> - 2004年03月03日 17:57:45
>>>>> "Phil" == Phil Erickson <pj...@ha...> writes:
 Phil> Hello John, I have run into the following minor matplotlib
 Phil> bug. Using the sample code below, the y axis label and tick
 Phil> marks in the second subplot seem not to be in the right
 Phil> places. Also on that second subplot, the first legend is
 Phil> missing when the window is initially drawn, but gets redrawn
 Phil> correctly if I use the x axis interactive scrolling buttons.
Hi Phil,
Wow, that was a subtle one. Thanks very much for a detailed
description, screenshot and demo code. You can distill the essence of
the bug in this script
 from matplotlib.matlab import *
 subplot(211)
 plot([1,2,3])
 ylabel('Test me')
 subplot(212)
 plot([1,2,3])
 ylabel('Test me')
 show()
The key observation is that this script exposes the bug, but
examples/subplot_demo.py does not. I found that if I commented out
the first ylabel the bug also disappeared. This led me to the
solution.
I cache font instances in many of the backends since font creation and
drawing can be expensive, particularly on the GTK backend for vertical
text where I have to do the rotation by hand, pixel-by-pixel in
python. In the cache I map text properties to font instances in a
dictionary. As one of the properties, I was using the x, and y coords
of the text in *user* rather than *display* coords, so the second
ylabel was using the cached information of the first. In the case of
the ylabels, the user coords are relative to their respective axes,
and so are identical for identical labels.
The same explanation applies to the legend code because the legends
had duplicate text.
A simple fix. In matplotlib.text.py, on or around line 118 replace
get_prop_tup with
 def get_prop_tup(self):
 """
 Return a hashable tuple of properties
 Not intended to be human readable, but useful for backends who
 want to cache derived information about text (eg layouts) and
 need to know if the text has changed
 """
 x, y = self.get_xy_display()
 return (x, y, self._text, self._color,
 self._verticalalignment, self._horizontalalignment,
 self._fontname, self._fontsize, self._fontweight,
 self._fontangle, self._rotation, self.dpi.get())
The key is to use the display coords for the cache value.
Thanks again,
JDH
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /