SourceForge logo
SourceForge logo
Menu

matplotlib-users — Discussion related to using matplotlib

You can subscribe to this list here.

2003 Jan
Feb
Mar
Apr
May
(3)
Jun
Jul
Aug
(12)
Sep
(12)
Oct
(56)
Nov
(65)
Dec
(37)
2004 Jan
(59)
Feb
(78)
Mar
(153)
Apr
(205)
May
(184)
Jun
(123)
Jul
(171)
Aug
(156)
Sep
(190)
Oct
(120)
Nov
(154)
Dec
(223)
2005 Jan
(184)
Feb
(267)
Mar
(214)
Apr
(286)
May
(320)
Jun
(299)
Jul
(348)
Aug
(283)
Sep
(355)
Oct
(293)
Nov
(232)
Dec
(203)
2006 Jan
(352)
Feb
(358)
Mar
(403)
Apr
(313)
May
(165)
Jun
(281)
Jul
(316)
Aug
(228)
Sep
(279)
Oct
(243)
Nov
(315)
Dec
(345)
2007 Jan
(260)
Feb
(323)
Mar
(340)
Apr
(319)
May
(290)
Jun
(296)
Jul
(221)
Aug
(292)
Sep
(242)
Oct
(248)
Nov
(242)
Dec
(332)
2008 Jan
(312)
Feb
(359)
Mar
(454)
Apr
(287)
May
(340)
Jun
(450)
Jul
(403)
Aug
(324)
Sep
(349)
Oct
(385)
Nov
(363)
Dec
(437)
2009 Jan
(500)
Feb
(301)
Mar
(409)
Apr
(486)
May
(545)
Jun
(391)
Jul
(518)
Aug
(497)
Sep
(492)
Oct
(429)
Nov
(357)
Dec
(310)
2010 Jan
(371)
Feb
(657)
Mar
(519)
Apr
(432)
May
(312)
Jun
(416)
Jul
(477)
Aug
(386)
Sep
(419)
Oct
(435)
Nov
(320)
Dec
(202)
2011 Jan
(321)
Feb
(413)
Mar
(299)
Apr
(215)
May
(284)
Jun
(203)
Jul
(207)
Aug
(314)
Sep
(321)
Oct
(259)
Nov
(347)
Dec
(209)
2012 Jan
(322)
Feb
(414)
Mar
(377)
Apr
(179)
May
(173)
Jun
(234)
Jul
(295)
Aug
(239)
Sep
(276)
Oct
(355)
Nov
(144)
Dec
(108)
2013 Jan
(170)
Feb
(89)
Mar
(204)
Apr
(133)
May
(142)
Jun
(89)
Jul
(160)
Aug
(180)
Sep
(69)
Oct
(136)
Nov
(83)
Dec
(32)
2014 Jan
(71)
Feb
(90)
Mar
(161)
Apr
(117)
May
(78)
Jun
(94)
Jul
(60)
Aug
(83)
Sep
(102)
Oct
(132)
Nov
(154)
Dec
(96)
2015 Jan
(45)
Feb
(138)
Mar
(176)
Apr
(132)
May
(119)
Jun
(124)
Jul
(77)
Aug
(31)
Sep
(34)
Oct
(22)
Nov
(23)
Dec
(9)
2016 Jan
(26)
Feb
(17)
Mar
(10)
Apr
(8)
May
(4)
Jun
(8)
Jul
(6)
Aug
(5)
Sep
(9)
Oct
(4)
Nov
Dec
2017 Jan
(5)
Feb
(7)
Mar
(1)
Apr
(5)
May
Jun
(3)
Jul
(6)
Aug
(1)
Sep
Oct
(2)
Nov
(1)
Dec
2018 Jan
Feb
Mar
Apr
(1)
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2020 Jan
Feb
Mar
Apr
May
(1)
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2025 Jan
(1)
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
S M T W T F S






1
(2)
2
(4)
3
(9)
4
(12)
5
(12)
6
(7)
7
(8)
8
(4)
9
(2)
10
(9)
11
(6)
12
(1)
13
(20)
14
(13)
15
(9)
16
(3)
17
(12)
18
(16)
19
(14)
20
(12)
21
(15)
22
(11)
23
(5)
24
(7)
25
(7)
26
(8)
27
(11)
28
(10)
29
(1)
30
(3)
31
(6)





Showing 9 results of 9

From: questions a. <que...@gm...> - 2011年10月03日 23:51:12
Hi All,
Is there a simple way to plot a directional arrow to represent a degree?
I have a netcdf file containing wind direction as degrees and I would like
to make a plot with all little arrows representing the wind direction.
Below is the code I am using currently to plot wind direction but am not
sure where/how to add directional arrows.
Thanks
from netCDF4 import Dataset
import numpy as N
import pylab as plt
from numpy import ma as MA
from mpl_toolkits.basemap import Basemap
import os
ncfile=Dataset('E:/WINDDIR/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc', 'r+',
'NETCDF4')
WDIR=ncfile.variables['Wind_Dir_SFC'][-50]
LAT=ncfile.variables['latitude'][:]
LON=ncfile.variables['longitude'][:]
TIME=ncfile.variables['time'][-50]
fillvalue=ncfile.variables['Wind_Dir_SFC']._FillValue
WDIR=MA.masked_values(WDIR, fillvalue)
ncfile.close()
map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
 llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
x,y=map(*N.meshgrid(LON,LAT))
map.drawstates()
map.drawcoastlines()
plt.title('Wind Direction')
CS = map.contourf(x,y,WDIR,15, cmap=plt.cm.jet)
l,b,w,h =0.1,0.1,0.8,0.8
cax = plt.axes([l+w+0.025, b, 0.025, h])
plt.colorbar(CS,cax=cax,drawedges=True)
plt.savefig((os.path.join('E:/WINDDIR/', 'WDIRSFC.png')))
plt.show()
From: Eric F. <ef...@ha...> - 2011年10月03日 23:14:04
On 10/03/2011 09:22 AM, Christopher Brown wrote:
> import matplotlib.pyplot as pp
> fig = pp.figure()
> ax1 = fig.add_subplot(111)
> ax2 = ax1.twinx()
> # works (tick labels are blue):
> for tick in ax1.yaxis.get_major_ticks():
> tick.label1.set_color('blue')
> # does not work (tick labels are not red):
> for tick in ax2.yaxis.get_major_ticks():
> tick.label1.set_color('red')
> pp.show()
Try this instead:
import matplotlib.pyplot as pp
fig = pp.figure()
ax1 = fig.add_subplot(111)
ax2 = ax1.twinx()
ax1.tick_params(axis='y', labelcolor='b')
ax2.tick_params(axis='y', labelcolor='r')
pp.show()
Eric
From: Benjamin R. <ben...@ou...> - 2011年10月03日 22:57:49
On Mon, Oct 3, 2011 at 2:22 PM, Christopher Brown <c-...@as...> wrote:
> Hi,
>
> Im running mpl 1.01 from sf installer with py2.7 on windows xp. Can
> anyone tell me what I am doing wrong in the following snippet:
>
> import matplotlib.pyplot as pp
> fig = pp.figure()
> ax1 = fig.add_subplot(111)
> ax2 = ax1.twinx()
> # works (tick labels are blue):
> for tick in ax1.yaxis.get_major_ticks():
> tick.label1.set_color('blue')
> # does not work (tick labels are not red):
> for tick in ax2.yaxis.get_major_ticks():
> tick.label1.set_color('red')
> pp.show()
>
>
Confirmed with the v1.1.x branch as well. Although, I don't play with
twinx() enough to know if this is really a bug or not, but my vote is that
it is a bug.
Ben Root
From: Christopher B. <c-...@as...> - 2011年10月03日 22:21:34
Hi,
Im running mpl 1.01 from sf installer with py2.7 on windows xp. Can 
anyone tell me what I am doing wrong in the following snippet:
import matplotlib.pyplot as pp
fig = pp.figure()
ax1 = fig.add_subplot(111)
ax2 = ax1.twinx()
# works (tick labels are blue):
for tick in ax1.yaxis.get_major_ticks():
 tick.label1.set_color('blue')
# does not work (tick labels are not red):
for tick in ax2.yaxis.get_major_ticks():
 tick.label1.set_color('red')
pp.show()
-- 
Christopher Brown, Ph.D.
Associate Research Professor
Department of Speech and Hearing Science
Arizona State University
http://pal.asu.edu
Hi again,
still trying to accomplish the filling of certain paths only inside U.S. It ocurred to me that set_clip_path could work but so far, I have not been able to show the curve in the map. 
Could someone point out what is missing? Thanks
#!/usr/bin/env python
"""http://www.scipy.org/Cookbook/Finding_Convex_Hull"""
import numpy as n, pylab as p, time
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import matplotlib.path as mpath
 
from matplotlib.patches import Polygon
from mpl_toolkits.basemap import Basemap
import sys
import numpy as np
import matplotlib.cm as cm
 
def _angle_to_point(point, centre):
 '''calculate angle in 2-D between points and x axis'''
 delta = point - centre
 res = n.arctan(delta[1] / delta[0])
 if delta[0] < 0:
 res += n.pi
 return res
 
 
def _draw_triangle(p1, p2, p3, **kwargs):
 tmp = n.vstack((p1,p2,p3))
 x,y = [x[0] for x in zip(tmp.transpose())]
 p.fill(x,y, **kwargs) # commented out to see result
 
 
def area_of_triangle(p1, p2, p3):
 '''calculate area of any triangle given co-ordinates of the corners'''
 return n.linalg.norm(n.cross((p2 - p1), (p3 - p1)))/2.
 
 
def convex_hull(points, graphic=True, smidgen=0.0075):
 '''Calculate subset of points that make a convex hull around points
 
Recursively eliminates points that lie inside two neighbouring points until only convex hull is remaining.
 
:Parameters:
 points : ndarray (2 x m)
 array of points for which to find hull
 graphic : bool
 use pylab to show progress?
 smidgen : float
 offset for graphic number labels - useful values depend on your data range
 
:Returns:
 hull_points : ndarray (2 x n)
 convex hull surrounding points
'''
# Commenting these 2 lines out shows the plotting of the country border
# if graphic:
# p.clf()
 n_pts = points.shape[1]
 print "POINTS shape[1]:%d" %(n_pts)
 assert(n_pts > 5)
 centre = points.mean(1)
 angles = n.apply_along_axis(_angle_to_point, 0, points, centre)
 pts_ord = points[:,angles.argsort()]
 pts = [x[0] for x in zip(pts_ord.transpose())]
 prev_pts = len(pts) + 1
 k = 0
 while prev_pts > n_pts:
 prev_pts = n_pts
 n_pts = len(pts)
 if graphic: p.gca().patches = []
 i = -2
 while i < (n_pts - 2):
 Aij = area_of_triangle(centre, pts[i], pts[(i + 1) % n_pts])
 Ajk = area_of_triangle(centre, pts[(i + 1) % n_pts], \
 pts[(i + 2) % n_pts])
 Aik = area_of_triangle(centre, pts[i], pts[(i + 2) % n_pts])
 if Aij + Ajk < Aik:
 if graphic: p.plot((pts[i + 1][0],),(pts[i + 1][1],)) # without green circle marker
 del pts[i+1]
 i += 1
 n_pts = len(pts)
 k += 1
 return n.asarray(pts)
 
if __name__ == "__main__":
 x1 = -124.
 x2 = -57.
 y1 = 18.
 y2 = 51.
 
 m = Basemap(resolution='i',projection='stere', lat_0=39., lon_0=-98.,llcrnrlat=y1,urcrnrlat=y2,llcrnrlon=x1,urcrnrlon=x2)
 point0 = []
 point1 = []
 cpaths = (m.drawcountries()).get_paths()
 for cpath in cpaths:
 vs = cpath.vertices
 for v in vs:
 x=v[0]
 y=v[1]
 point0.append(x)
 point1.append(y)
 nonumpy = []
 nonumpy.append(point0)
 nonumpy.append(point1)
 points = n.array(nonumpy)
 hull_pts = convex_hull(points)
 poly = Polygon(hull_pts)
 USpath = poly.get_path()
 USpatch = mpatches.PathPatch(USpath,facecolor='none',edgecolor='none')
 ax = plt.gca()
 ax.add_patch(USpatch)
 
 # Add my curve
 Path = mpath.Path
 pathdata = []
 pathdata.append((Path.MOVETO,m(-120.,35.)))
 pathdata.append((Path.LINETO,m(-100.,35.)))
 pathdata.append((Path.LINETO,m(-100.,30.)))
 pathdata.append((Path.LINETO,m(-90.,28.)))
 pathdata.append((Path.LINETO,m(-90,25)))
 pathdata.append((Path.LINETO,m(-100,25)))
 pathdata.append((Path.CURVE3,m(-120.,35.)))
 
 codes,verts = zip(*pathdata)
 im = ax.imshow(verts,cmap=cm.gray,clip_path=USpatch,clip_on=True)
 im.set_clip_path(USpatch)
 m.drawparallels(np.arange(20,60,5),labels=[1,0,0,0],color='black')
 m.drawmeridians(np.arange(-140,60,10),labels=[0,0,0,1],color='black')
 plt.gcf().savefig('./ch.png')
From: John L. <joh...@sb...> - 2011年10月03日 21:09:04
Hi, folks,
I will be posting this question to both matplotlib-users and
wxpython-users. Apologies to those of you who have to endure my
ramblings two times in a row!
Using this example by John Bender,
http://www.scipy.org/Matplotlib_figure_in_a_wx_panel
I recently constructed a working, animated matplotlib graph in a
wxPython frame. A sample output is here:
http://www.flickr.com/photos/15579975@N00/6145518550
In that example, the text block is in wxPython, and the color bar for
the graph's Z scale is a bitmap object which is again handled by wx.
Only the live graph is rendered by matplotlib.
 
Once I accomplished this, I attempted a more complicated,
multiple-subplot display, this time with the text boxes handled my
matplotlib rather than wx. I also tried removing parts of Mr. Bender's
code that I thought that I would not need. Specifically, I've disabled
resizing of my matplotlib panel. But when I removed the code associated
with sizing, I discovered that my animation disappeared. The first
frame would draw, then nothing.
Digging deeper, I learned that redrawing is SOMEHOW accomplished in the
PlotPanel._SetSize method. _SetSize is called when there's a wx.IDLE
message. In _SetSize, you have to call PlotPanel.SetSize (note, no
underscore this time) and FigureCanvasWxAgg.SetSize on EVERY cycle to
make animation work. The matplotlib figure.set_size method needs only
to be called the first time -- at least, in my case, where I've disabled
resizing. I haven't tested a resizable window.
Here are my questions.
1) I do not recall seeing this kind of behavior in wxPython before. Why
does wxPython treat matplotlib objects differently?
2) How exactly is sizing making the redrawing happen? Is this a good
method to use? The indirect nature of this redrawing-by-sizing approach
sent me on a long and pointless hunt for bugs in my own code. Finally,
how can I determine how MUCH redrawing is taking place on my matplotlib
canvas? I am trying to implement eight image plots simultaneously, with
some overlaid contours, and some live text, too. But sometimes I only
have to update four of the eight plots, or just the text. Does
matplotlib know which parts of its image are "dirty" and confine its
updates appropriately?
Many thanks for your insights!
From: Michael C. <fat...@ya...> - 2011年10月03日 19:50:05
Hello,
I am using Matplotlib 1.0.0 in Python 2.6.
I am trying to plot time series data of unique IDs and color the points
based on location. Each data point has a unique ID value, a date value, and
a location value.
The unique IDs and date values are plotting fine but I am unable to control
the color and subsequently the legend.
Here is a sample of the data.
IDs = [47, 33, 47, 12, 50, 50, 27, 27, 16, 27]
locations = ['201', '207', '207', '205', '204', '201', '209', '209',
'207','207']
dates = [ 733315.83240741, 733315.83521991, 733315.83681713,
 733315.83788194, 733336.54554398, 733336.54731481,
 733337.99842593, 733337.99943287, 733338.00070602,
 733338.00252315]
This basic code works.
fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(dates,IDs,marker='d')
ax.xaxis_date()
fig.autofmt_xdate()
plt.grid(True)
plt.show()
I've been trying to figure out how to set color = locations with no success.
Any ideas out there?
Thanks,
Mike
-- 
View this message in context: http://old.nabble.com/color-problems-in-scatter-plot-tp32584727p32584727.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
From: Benjamin R. <ben...@ou...> - 2011年10月03日 13:27:15
> Does the installation page needs updating?
> http://matplotlib.sourceforge.net/users/installing.html#building-on-osx
Yes. I made several changes to those docs for the v1.1.0 release.
Hopefully, it will make things clearer.
Ben Root
From: Gavin K. <gav...@gm...> - 2011年10月03日 05:37:42
Dear Scott & Bryan,
Thanks for the advice!
Neither the dmg nor the supposedly 32bit egg on sourceforge worked for
me, even after I deleted 64bit Python 2.7.2. @Bryan: Thanks for
suggesting MacPorts: I didn't know about that and you are right that
that would have been a good solution.
Here is how I solved it (with serious help from a friend):
The problem seems to be that tcl/tk on MacOSX is 32bit, which is why
there is no 64bit Mac distribution on sourceforge.
I downloaded the source from sourceforge (matplotlib_1.0.1.tar.gz)
then expanded it into a temp directory.
In the root directory,
cp setupext.py.template setup.py
I uncommented line 11
basedir=/usr
and changed it to
basedir=/usr/X11
Then in setupext.py, line 832, I removed
[-2]
(as suggested by old.nabble.com/Can't-install-from-PyPi-td32404788.html)
Then "python setup.py install" (do not use "build").
And that was all done.
Another solution might be to build 64bit Tcl/Tk on MacOSX.
Instructions are here:
http://buffalothedestroyer.blogspot.com/2009/07/installing-64-bit-tcltk-on-mac-os-x.html
http://bugs.python.org/issue6441
but I have not tried this and it seems like this solution needs python
to be rebuilt as well.
Does the installation page needs updating?
http://matplotlib.sourceforge.net/users/installing.html#building-on-osx
I'm copying this e-mail to the list so it is archived. Gavin.
On 2 October 2011 23:05, Scott Lasley <sl...@sp...> wrote:
>
> On Oct 2, 2011, at 9:10 AM, Gavin Koh wrote:
>
>> Dear all,
>>
>> Just installed Python 2.7.2 on my Mac running OSX 10.6. Installed
>> numpy 1.6.1 and scipy 0.9.0 both from the dmg's downloaded from scipy.
>> Just tried to install matplotlib but there is no 64bit dmg available.
>> Tried installing from the egg instead, but that doesn't help.
>> Am getting
>> ImportError: dlopen(/Library/Python/2.7/site-packages/matplotlib-1.0.1_r0-py2.7-macosx-10.3-fat.egg/matplotlib/_path.so,
>> 2): no suitable image found. Did find:
>>    /Library/Python/2.7/site-packages/matplotlib-1.0.1_r0-py2.7-macosx-10.3-fat.egg/matplotlib/_path.so:
>> no matching architecture in universal wrapper
>> Trying to build from source but failing desperately. Help, please?
>
> This site helped me to build matplotlib for OS X a while back - http://blog.hyperjeff.net/?p=160
> Since you already have python 2.7.2, numpy and scipy installed, you can probably skip down to the section on building matplotlib. Some information on the page is out of date. For example, the source is now on github at https://github.com/matplotlib/matplotlib
>
> I use the gfortran compiler from the R project page - http://r.research.att.com/tools/
>
> I am by no means an expert at building matplotlib, but I'm happy to help if you still have problems getting it running on your mac.
-- 
Hofstadter's Law: It always takes longer than you expect, even when
you take into account Hofstadter's Law.
—Douglas Hofstadter (in Gödel, Escher, Bach, 1979)

Showing 9 results of 9

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 によって変換されたページ (->オリジナル) /