## matplotlib-users

 [Matplotlib-users] logairthmic contour plot From: jonasr - 2012-06-13 17:31:28 ```Hi, im actually trying to make a countour plot Z=f(X,Y) from two variables X,Y . My Problem is that i have to use a logarithmic scale for the Z values. If i plot the data with the logarithmic scale it gets pretty ugly, because i have a lot of values which are zero, which means on the log scale the value goes to -inf. Here is an example what i mean http://www.imagebanana.com/view/qh1khpxp/example.png I acutally have no idea how to make the plot look better, maybe somebody has an idea ? thank you -- View this message in context: http://old.nabble.com/logairthmic-contour-plot-tp34007155p34007155.html Sent from the matplotlib - users mailing list archive at Nabble.com. ```
 Re: [Matplotlib-users] logairthmic contour plot From: Eric Firing - 2012-06-13 18:33:38 ```On 06/13/2012 07:31 AM, jonasr wrote: > > Hi, > > im actually trying to make a countour plot Z=f(X,Y) from two variables X,Y . > My Problem is that i have to use a logarithmic scale for the Z values. > If i plot the data with the logarithmic scale it gets pretty ugly, because i > have a lot of values which are zero, > which means on the log scale the value goes to -inf. > Here is an example what i mean > > http://www.imagebanana.com/view/qh1khpxp/example.png > > I acutally have no idea how to make the plot look better, > maybe somebody has an idea ? Use np.ma.masked_less to mask out values below some threshold before taking the log. e.g., import matplotlib.pyplot as plt import numpy as np x = np.arange(0, 1, 0.01) y = np.arange(0, 8, 0.05) X, Y = np.meshgrid(x, y) Z = 10 ** (-5 + 11 * X * np.sin(Y)) Z = np.ma.masked_less(Z, 1e-4) Zlog = np.ma.log10(Z) CS = plt.contourf(X, Y, Zlog, levels=np.arange(-3, 5.01, 1.0), extend='both') plt.colorbar() Eric > > thank you ```
 [Matplotlib-users] Scatter legend woes. From: Steven Boada - 2012-06-13 19:34:44 ```Whoops, I forgot to change the subject. Sorry list. List, I'm making a scatter plot using a for loop. Here's a simple example.. for i in range(10): x=rand() y=rand() scatter(x,y,label='point') legend() show() When you do this, you get a legend entry for every single point. In this case, I get 9 entries in my legend. Is there a way to only get a single entry? I have looked into creating the legends by hand, but I'm not having much luck. Googling, only turned up a single example of someone else with the same problem. Help me list, you're my only hope. Steven On 06/13/2012 01:33 PM, Eric Firing wrote: > On 06/13/2012 07:31 AM, jonasr wrote: >> Hi, >> >> im actually trying to make a countour plot Z=f(X,Y) from two variables X,Y . >> My Problem is that i have to use a logarithmic scale for the Z values. >> If i plot the data with the logarithmic scale it gets pretty ugly, because i >> have a lot of values which are zero, >> which means on the log scale the value goes to -inf. >> Here is an example what i mean >> >> http://www.imagebanana.com/view/qh1khpxp/example.png >> >> I acutally have no idea how to make the plot look better, >> maybe somebody has an idea ? > Use np.ma.masked_less to mask out values below some threshold before > taking the log. > > e.g., > > import matplotlib.pyplot as plt > import numpy as np > x = np.arange(0, 1, 0.01) > y = np.arange(0, 8, 0.05) > X, Y = np.meshgrid(x, y) > Z = 10 ** (-5 + 11 * X * np.sin(Y)) > Z = np.ma.masked_less(Z, 1e-4) > Zlog = np.ma.log10(Z) > CS = plt.contourf(X, Y, Zlog, levels=np.arange(-3, 5.01, 1.0), > extend='both') > plt.colorbar() > > > > Eric > >> thank you > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- Steven Boada Dept. Physics and Astronomy Texas A&M University boada@... ```
 Re: [Matplotlib-users] Scatter legend woes. From: pybokeh - 2012-06-13 20:01:33 Attachments: Message as HTML ```Are you trying to make 9 scatter plots? In your for loop, if you are trying to make a set of x values and a set of y values, then I think this is wrong. Since you didn't provide import statements I don't know which rand() function you are using. Assuming it is scipy.rand(), you will only have one x value and one y value, not much of scatter chart with just one point :-) Otherwise, Mike's suggestion is valid. Regards, Daniel On Jun 13, 2012 3:35 PM, "Steven Boada" wrote: > Whoops, I forgot to change the subject. Sorry list. > > List, > > I'm making a scatter plot using a for loop. Here's a simple example.. > > for i in range(10): > x=rand() > y=rand() > scatter(x,y,label='point') > > legend() > show() > > > When you do this, you get a legend entry for every single point. In this > case, I get 9 entries in my legend. > > Is there a way to only get a single entry? I have looked into creating > the legends by hand, but I'm not having much luck. Googling, only turned > up a single example of someone else with the same problem. > > Help me list, you're my only hope. > > Steven > > On 06/13/2012 01:33 PM, Eric Firing wrote: > > On 06/13/2012 07:31 AM, jonasr wrote: > >> Hi, > >> > >> im actually trying to make a countour plot Z=f(X,Y) from two variables > X,Y . > >> My Problem is that i have to use a logarithmic scale for the Z values. > >> If i plot the data with the logarithmic scale it gets pretty ugly, > because i > >> have a lot of values which are zero, > >> which means on the log scale the value goes to -inf. > >> Here is an example what i mean > >> > >> http://www.imagebanana.com/view/qh1khpxp/example.png > >> > >> I acutally have no idea how to make the plot look better, > >> maybe somebody has an idea ? > > Use np.ma.masked_less to mask out values below some threshold before > > taking the log. > > > > e.g., > > > > import matplotlib.pyplot as plt > > import numpy as np > > x = np.arange(0, 1, 0.01) > > y = np.arange(0, 8, 0.05) > > X, Y = np.meshgrid(x, y) > > Z = 10 ** (-5 + 11 * X * np.sin(Y)) > > Z = np.ma.masked_less(Z, 1e-4) > > Zlog = np.ma.log10(Z) > > CS = plt.contourf(X, Y, Zlog, levels=np.arange(-3, 5.01, 1.0), > > extend='both') > > plt.colorbar() > > > > > > > > Eric > > > >> thank you > > > > > ------------------------------------------------------------------------------ > > Live Security Virtual Conference > > Exclusive live event will cover all the ways today's security and > > threat landscape has changed and how IT managers can respond. Discussions > > will include endpoint security, mobile security and the latest in malware > > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > > _______________________________________________ > > Matplotlib-users mailing list > > Matplotlib-users@... > > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > > > -- > Steven Boada > Dept. Physics and Astronomy > Texas A&M University > boada@... > > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > ```
 Re: [Matplotlib-users] Scatter legend woes. From: Mike Kaufman - 2012-06-13 19:56:59 ```On 6/13/12 3:23 PM, Steven Boada wrote: > Whoops, I forgot to change the subject. Sorry list. > > List, > > I'm making a scatter plot using a for loop. Here's a simple example.. > > for i in range(10): > x=rand() > y=rand() > scatter(x,y,label='point') > > legend() > show() > > > When you do this, you get a legend entry for every single point. In this > case, I get 9 entries in my legend. > > Is there a way to only get a single entry? I have looked into creating > the legends by hand, but I'm not having much luck. Googling, only turned > up a single example of someone else with the same problem. > > Help me list, you're my only hope. Perhaps not exactly what you want, but an answer is don't use a loop: x = rand(10) y = rand(10) scatter(x,y, label='points') legend() draw() show() Of course if you want to color each point differently, then this won't work. M ```
 Re: [Matplotlib-users] Scatter legend woes. From: Paul Kuin - 2012-06-13 20:11:10 ```I have a routine where I start outside the loop with and empty sequence > leg = [] then add at each iteration the label > leg.append('mylabel') then call legend with the sequence at the end > legend(leg) I think I once truncated the list and got part only > legend(leg[:2]) It depends on what you want to do. Paul On Wed, Jun 13, 2012 at 8:56 PM, Mike Kaufman wrote: > On 6/13/12 3:23 PM, Steven Boada wrote: >> Whoops, I forgot to change the subject. Sorry list. >> >> List, >> >> I'm making a scatter plot using a for loop. Here's a simple example.. >> >> for i in range(10): >>       x=rand() >>       y=rand() >>       scatter(x,y,label='point') >> >> legend() >> show() >> >> >> When you do this, you get a legend entry for every single point. In this >> case, I get 9 entries in my legend. >> >> Is there a way to only get a single entry? I have looked into creating >> the legends by hand, but I'm not having much luck. Googling, only turned >> up a single example of someone else with the same problem. >> >> Help me list, you're my only hope. > > Perhaps not exactly what you want, but an answer is don't use a loop: > > x = rand(10) > y = rand(10) > scatter(x,y, label='points') > legend() > draw() > show() > > Of course if you want to color each point differently, then this won't work. > > M > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- * * * * * * * * http://www.mssl.ucl.ac.uk/~npmk/ * * * * Dr. N.P.M. Kuin      (npmk@...) phone +44-(0)1483 (prefix) -204256 (work) -276110 (home) mobile +44(0)7806985366  skype ID: npkuin Mullard Space Science Laboratory  – University College London  – Holmbury St Mary – Dorking – Surrey RH5 6NT–  U.K. ```
 Re: [Matplotlib-users] Scatter legend woes. From: Goyo - 2012-06-13 20:17:57 ```2012/6/13 Mike Kaufman : > On 6/13/12 3:23 PM, Steven Boada wrote: >> Whoops, I forgot to change the subject. Sorry list. >> >> List, >> >> I'm making a scatter plot using a for loop. Here's a simple example.. >> >> for i in range(10): >>       x=rand() >>       y=rand() >>       scatter(x,y,label='point') >> >> legend() >> show() >> >> >> When you do this, you get a legend entry for every single point. In this >> case, I get 9 entries in my legend. >> >> Is there a way to only get a single entry? Maybe you can adapt this to your use case: for i in range(10): x=rand() y=rand() collection = scatter(x,y,label='point') legend((collection,), ('Label',)) show() Goyo ```
 Re: [Matplotlib-users] Scatter legend woes. From: Steven Boada - 2012-06-13 20:06:32 Attachments: Message as HTML ```Well I am doing a lot more than this simple example shows. Point is that there are nine different points each with their own legend entry. I could put it all out of the for loops, but it is all already written, and I'd rather just fix the legend at the end than move sections of the code around. I'm willing to do it, if that is the only choice, but I wanted to ask before I commit my time. Wouldn't it be a good (smart) thing for the code to lump all the points with the same label together? This would be a great feature to be added IMO. S On 06/13/2012 03:01 PM, pybokeh wrote: > > Are you trying to make 9 scatter plots? In your for loop, if you are > trying to make a set of x values and a set of y values, then I think > this is wrong. Since you didn't provide import statements I don't > know which rand() function you are using. Assuming it is > scipy.rand(), you will only have one x value and one y value, not much > of scatter chart with just one point :-) > > Otherwise, Mike's suggestion is valid. > > Regards, > Daniel > > On Jun 13, 2012 3:35 PM, "Steven Boada" > wrote: > > Whoops, I forgot to change the subject. Sorry list. > > List, > > I'm making a scatter plot using a for loop. Here's a simple example.. > > for i in range(10): > x=rand() > y=rand() > scatter(x,y,label='point') > > legend() > show() > > > When you do this, you get a legend entry for every single point. > In this > case, I get 9 entries in my legend. > > Is there a way to only get a single entry? I have looked into creating > the legends by hand, but I'm not having much luck. Googling, only > turned > up a single example of someone else with the same problem. > > Help me list, you're my only hope. > > Steven > > On 06/13/2012 01:33 PM, Eric Firing wrote: > > On 06/13/2012 07:31 AM, jonasr wrote: > >> Hi, > >> > >> im actually trying to make a countour plot Z=f(X,Y) from two > variables X,Y . > >> My Problem is that i have to use a logarithmic scale for the Z > values. > >> If i plot the data with the logarithmic scale it gets pretty > ugly, because i > >> have a lot of values which are zero, > >> which means on the log scale the value goes to -inf. > >> Here is an example what i mean > >> > >> http://www.imagebanana.com/view/qh1khpxp/example.png > >> > >> I acutally have no idea how to make the plot look better, > >> maybe somebody has an idea ? > > Use np.ma.masked_less to mask out values below some threshold before > > taking the log. > > > > e.g., > > > > import matplotlib.pyplot as plt > > import numpy as np > > x = np.arange(0, 1, 0.01) > > y = np.arange(0, 8, 0.05) > > X, Y = np.meshgrid(x, y) > > Z = 10 ** (-5 + 11 * X * np.sin(Y)) > > Z = np.ma.masked_less(Z, 1e-4) > > Zlog = np.ma.log10(Z) > > CS = plt.contourf(X, Y, Zlog, levels=np.arange(-3, 5.01, 1.0), > > extend='both') > > plt.colorbar() > > > > > > > > Eric > > > >> thank you > > > > > ------------------------------------------------------------------------------ > > Live Security Virtual Conference > > Exclusive live event will cover all the ways today's security and > > threat landscape has changed and how IT managers can respond. > Discussions > > will include endpoint security, mobile security and the latest > in malware > > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > > _______________________________________________ > > Matplotlib-users mailing list > > Matplotlib-users@... > > > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > > > -- > Steven Boada > Dept. Physics and Astronomy > Texas A&M University > boada@... > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. > Discussions > will include endpoint security, mobile security and the latest in > malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@... > > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- Steven Boada Dept. Physics and Astronomy Texas A&M University boada@... ```
 Re: [Matplotlib-users] Scatter legend woes. From: Mike Kaufman - 2012-06-13 20:22:54 ```On 6/13/12 4:06 PM, Steven Boada wrote: > > Well I am doing a lot more than this simple example shows. Point is that > there are nine different points each with their own legend entry. > > I could put it all out of the for loops, but it is all already written, > and I'd rather just fix the legend at the end than move sections of the > code around. I'm willing to do it, if that is the only choice, but I > wanted to ask before I commit my time. > > Wouldn't it be a good (smart) thing for the code to lump all the points > with the same label together? This would be a great feature to be added IMO. Assuming that you already have ten scatter plots, change the labels on the ones you don't want in the legend to '_nolegend_' (see help(legend)) for i in range(10): gca().collections[i].set_label('_nolegend_') gca().collections[0].set_label('the one label I want') legend() draw() M ```
 Re: [Matplotlib-users] Scatter legend woes. From: Steven Boada - 2012-06-13 20:32:19 ```The gca().collections.set_label('label') works great. Admittedly, I'm not sure why it works. I'm not that great with the collections stuff. But thanks! S On 06/13/2012 03:22 PM, Mike Kaufman wrote: > On 6/13/12 4:06 PM, Steven Boada wrote: >> Well I am doing a lot more than this simple example shows. Point is that >> there are nine different points each with their own legend entry. >> >> I could put it all out of the for loops, but it is all already written, >> and I'd rather just fix the legend at the end than move sections of the >> code around. I'm willing to do it, if that is the only choice, but I >> wanted to ask before I commit my time. >> >> Wouldn't it be a good (smart) thing for the code to lump all the points >> with the same label together? This would be a great feature to be added IMO. > Assuming that you already have ten scatter plots, change the labels on > the ones you don't want in the legend to '_nolegend_' (see help(legend)) > > for i in range(10): > gca().collections[i].set_label('_nolegend_') > gca().collections[0].set_label('the one label I want') > legend() > draw() > > M > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- Steven Boada Dept. Physics and Astronomy Texas A&M University boada@... ```
 Re: [Matplotlib-users] logairthmic contour plot From: Steven Boada - 2012-06-13 19:56:14 ```List, I'm making a scatter plot using a for loop. Here's a simple example.. for i in range(10): x=rand() y=rand() scatter(x,y,label='point') legend() show() When you do this, you get a legend entry for every single point. In this case, I get 9 entries in my legend. Is there a way to only get a single entry? I have looked into creating the legends by hand, but I'm not having much luck. Googling, only turned up a single example of someone else with the same problem. Help me list, you're my only hope. Steven ```
 Re: [Matplotlib-users] logairthmic contour plot From: Daπid - 2012-06-14 22:49:54 ```First, this is another topic, so please, change the subject of the message so it doesn't get messed up with others (and possible help lost in the process). Now, you are indeed plotting one dot at the time and generating a label for it. If you don't want that, you have to plot the whole list at the time: x=[rand() for i in xrange(10)] y=[rand() for i in xrange(10)] scatter(x,y, label='points') legend() show() where the definition of x includes a list comprehension (equivalent at "for i in xrange(10): x.append(rand())" ). On another topic, people are not usually fan of using from MODULEX import *, as it can turn into poor code and name collisions. It is nicer if you write "import pylab as plt", and refer to the functions as plt.scatter and so on. Regards. On Wed, Jun 13, 2012 at 9:21 PM, Steven Boada wrote: > List, > > I'm making a scatter plot using a for loop. Here's a simple example.. > > for i in range(10): >     x=rand() >     y=rand() >     scatter(x,y,label='point') > > legend() > show() > > > When you do this, you get a legend entry for every single point. In this > case, I get 9 entries in my legend. > > Is there a way to only get a single entry? I have looked into creating > the legends by hand, but I'm not having much luck. Googling, only turned > up a single example of someone else with the same problem. > > Help me list, you're my only hope. > > Steven > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users ```
 Re: [Matplotlib-users] logairthmic contour plot From: Benjamin Root - 2012-06-14 23:58:25 Attachments: Message as HTML ```On Thursday, June 14, 2012, Daπid wrote: > First, this is another topic, so please, change the subject of the > message so it doesn't get messed up with others (and possible help > lost in the process). > > Now, you are indeed plotting one dot at the time and generating a > label for it. If you don't want that, you have to plot the whole list > at the time: > > > x=[rand() for i in xrange(10)] > y=[rand() for i in xrange(10)] > > scatter(x,y, label='points') > legend() > show() > > where the definition of x includes a list comprehension (equivalent at > "for i in xrange(10): x.append(rand())" ). > > On another topic, people are not usually fan of using from MODULEX > import *, as it can turn into poor code and name collisions. It is > nicer if you write "import pylab as plt", and refer to the functions > as plt.scatter and so on. > > > Regards. Point of style: in general, yes, but pylab was intended for that to help transition matlab users. Pylab really shouldn't be loaded as plt, because that is what pyplot is usually imported as. Of course, this is all just a matter of style and preference. Cheers ! Ben Root ```
 Re: [Matplotlib-users] logairthmic contour plot From: Daπid - 2012-06-13 22:49:20 ```If all your values are positive (and you are sure of it), you could use the SymmetricalLogScale It uses log scale for large values (both positive and negative), and linear for small ones. http://matplotlib.sourceforge.net/devel/add_new_projection.html I believe there is a way to do it without going symetrical (ie, only defined for positive values), but I am unable to find it. On Wed, Jun 13, 2012 at 7:31 PM, jonasr wrote: > > Hi, > > im actually trying to make a countour plot Z=f(X,Y) from two variables X,Y . > My Problem is that i have to use a logarithmic scale for the Z values. > If i plot the data with the logarithmic scale it gets pretty ugly, because i > have a lot of values which are zero, > which means on the log scale the value goes to -inf. > Here is an example what i mean > > http://www.imagebanana.com/view/qh1khpxp/example.png > > I acutally have no idea how to make the plot look better, > maybe somebody has an idea ? > > thank you > -- > View this message in context: http://old.nabble.com/logairthmic-contour-plot-tp34007155p34007155.html > Sent from the matplotlib - users mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users ```