[Matplotlib-users] Size of an OffsetImage when saving as PDF?

2012-12-06 Thread Jeroen Hegeman
Dear Matplotlibers,

I'm trying to insert a logo image (from PNG) in the top left corner of my axes. 
I'm doing this by reading the logo using read_png() and inserting it as an 
OffsetImage in an AnnotationBox. When saving the figure as PNG everything is 
based on pixel sizes and I know how to scale the OffsetImage such that I end up 
with the desired logo size (based on the figure and logo sizes in pixels). 
Saving as PDF, however, does not depend on pixel sizes, and I end up with a 
'different' size of the logo.

Could someone please tell me what determines the size of the OffsetImage when 
saving as PDF? And maybe even better, how to achieve scaling that results in 
the same size logo as in the PNG output?

I have attached:
1a) A small test.py script that produces PNG and PDF output showing the 
different logo sizes. Uncommenting the zoom_factor line shows how to scale the 
logo independent of the figure size/dpi settings.
1b) A dummy PNG logo file.
2) Two example output files (PNG and PDF) showing the output of test.py.

Any hints would be much appreciated!

Best regards,
Jeroen


<>

test.pdf
Description: Adobe PDF document
<>#!/usr/bin/env python

import matplotlib
from matplotlib import pyplot as plt

import numpy as np

from matplotlib._png import read_png
from matplotlib.offsetbox import OffsetImage
from matplotlib.offsetbox import AnnotationBbox

if __name__ == "__main__":

matplotlib.rcParams["figure.figsize"] = (8., 6.)
matplotlib.rcParams["figure.dpi"] = 200
matplotlib.rcParams["savefig.dpi"] = matplotlib.rcParams["figure.dpi"]

fig = plt.figure()
ax = fig.add_subplot(111)

logo_data = read_png("dummy.png")
fig_dpi = ax.get_figure().dpi
fig_size = ax.get_figure().get_size_inches()

zoom_factor = 1.
# zoom_factor = .1 * fig_dpi * fig_size[0] / np.shape(logo_data)[0]

logo_box = OffsetImage(logo_data, zoom=zoom_factor)
ann_box = AnnotationBbox(logo_box, [0., 1.],
 xybox=(2., -3.),
 xycoords="axes fraction",
 boxcoords="offset points",
 box_alignment=(0., 1.),
 pad=0., frameon=False)
ax.add_artist(ann_box)

fig.savefig("test.png")
fig.savefig("test.pdf")

plt.close()
--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] plotting time series of bits

2012-12-06 Thread Oliver King
Hi Luke,


> I been able to use the bitwise_and() and right_shift() on the data to
> get individual arrays which are populated with only 0's and1's.
> 
> What I'm not clear on is now how to get the solid filled rectangle for
> areas where the bit is high and nothing when the bit is low.
> 
> Is there already this functionality somewhere in matplotlib?  I looked
> in the gallery and couldn't find anything quite like what I'm looking
> for, though I may have simply missed it.  If there isn't, I'm sure
> there is a way to do it, does anybody have any recommendations as to
> the path of least resistance?

How about using imshow()? Turn your individual arrays into a three-dimensional 
array of (r,g,b,a) values (MxNx4 array). You can then overwrite the axis labels 
(pixel numbers) with the boolean state descriptors and the time stamps. 

Cheers,
Oliver



--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] plotting time series of bits

2012-12-06 Thread Jason Grout
On 12/5/12 8:36 PM, Dale Lukas Peterson wrote:
> I have a time series of 32-bit unsigned integers in the form of a
> numpy array with dtype=numpy.uint32.  The bits of each integer in
> array correspond to various boolean states collected during an
> experiment.  I would like to make a plot this data in the following
> way:
> 1)  time on the horizontal axis (I have a time array of the same
> length as my integer array)
> 2)  bit position N on the vertical axis (0-1 corresponds to bit 0, 1-2
> corresponds to bit 1, etc.)
> 3)  a solid filled rectangle from (t1, N) to (t1+dt, N+1) whenever the
> bit is high.
>
> I been able to use the bitwise_and() and right_shift() on the data to
> get individual arrays which are populated with only 0's and1's.
>
> What I'm not clear on is now how to get the solid filled rectangle for
> areas where the bit is high and nothing when the bit is low.
>
> Is there already this functionality somewhere in matplotlib?  I looked
> in the gallery and couldn't find anything quite like what I'm looking
> for, though I may have simply missed it.  If there isn't, I'm sure
> there is a way to do it, does anybody have any recommendations as to
> the path of least resistance?

Just FYI, this reminds me a lot of the recent EventRaster discussion:

http://thread.gmane.org/gmane.comp.python.matplotlib.devel/11458/focus=11655

Thanks,

Jason



--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Varying alpha in ListedColormap not working

2012-12-06 Thread Oliver King
Incidentally, if anyone else wants to do this and is unable to update their 
matplotlib to v1.2.0, this code snippet achieves the same effect.

###
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.collections import LineCollection

# the line to plot
x = np.linspace(0,1,101)
y = x*0.5-0.25
scaling = np.exp(-(x-0.5)**2/0.5**2) # scale the transparency of the line 
according to this

points = np.array([x, y]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1], points[1:]], axis=1)

smin = scaling.min()
smax = scaling.max()
# inline function to convert scaling value to alpha value in [0,1]
alpha = lambda s0: (s0-smin)/(smax-smin)

# create a (r,g,b,a) color description for each line segment
cmap = []
for a in segments:
# the x-value for this segment is:
x0 = a.mean(0)[0]
# so it has a scaling value of:
s0 = np.interp(x0,x,scaling)
# and it has an alpha value of:
a0 = alpha(s0)
cmap.append([0.0,0.0,0.0,a0])

# Create the line collection object, and set the color parameters.
lc = LineCollection(segments)
lc.set_color(cmap)

ax = plt.subplot(111)
ax.add_collection(lc)
ax.set_xlim(x.min(), x.max())
ax.set_ylim(y.min(), y.max())
plt.show()
###


--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users