473,569 Members | 2,664 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Matplotlib logarithmic scatter plot

Can anyone give any suggestions on how to make a logarithmic (base 10)
x and y axis (loglog) plot in matplotlib? The scatter function doesn't
seem to have any log functionality built into it.

Thanks,
Derek Basch

P.S. I suck at math so feel free to make me feel stupid if it is really
easy to do :).

Feb 27 '06 #1
8 30476
Bas
Try this, don't know if this works for al versions:

from pylab import *
x=10**linspace( 0,5,100)
y=1/(1+x/1000)
loglog(x,y)
show()

If you only need a logarithm along one axis you can use semilogx() or
semilogy(). For more detailed questions go to the matplotlib mailing
list.

Cheers,
Bas

Feb 27 '06 #2
Thanks for the reply. I need a scatter plot though. Can that be done?

Feb 27 '06 #3
>>>>> "Derek" == Derek Basch <db****@yahoo.c om> writes:

Derek> Thanks for the reply. I need a scatter plot though. Can
Derek> that be done?

You can set the scale of xaxis and yaxis to either log or linear for
scatter plots

In [33]: ax = subplot(111)

In [34]: ax.scatter( 1e6*rand(1000), rand(1000))
Out[34]: <matplotlib.col lections.Regula rPolyCollection instance at
0x9c32fac>

In [35]: ax.set_xscale(' log')

In [36]: ax.set_xlim(1e-6,1e6)
Out[36]: (9.999999999999 9995e-07, 1000000.0)

In [37]: draw()

Feb 27 '06 #4
Great! That worked fine after I played with it for a bit. One last
question though. How do I label the ticks with the product of the
exponentiation? For instance:

100

instead of

10**2

Thanks for all the help,
Derek Basch

Feb 28 '06 #5
>>>>> "Derek" == Derek Basch <db****@yahoo.c om> writes:

Derek> Great! That worked fine after I played with it for a
Derek> bit. One last question though. How do I label the ticks
Derek> with the product of the exponentiation? For instance:

Derek> 100

Derek> instead of

Derek> 10**2

You can supply your own custom tick formatters (and locators). See

http://matplotlib.sf.net/matplotlib.ticker.html

and examples

http://matplotlib.sourceforge.net/ex...tom_ticker1.py
http://matplotlib.sourceforge.net/ex...minor_demo1.py
http://matplotlib.sourceforge.net/ex...minor_demo2.py

JDH
Feb 28 '06 #6
Thanks again. Here is the finished product. Maybe it will help someone
in the future:

from pylab import *

def log_10_product( x, pos):
"""The two args are the value and tick position.
Label ticks with the product of the exponentiation" ""
return '%1i' % (x)

ax = subplot(111)
# Axis scale must be set prior to declaring the Formatter
# If it is not the Formatter will use the default log labels for ticks.
ax.set_xscale(' log')
ax.set_yscale(' log')

formatter = FuncFormatter(l og_10_product)
ax.xaxis.set_ma jor_formatter(f ormatter)
ax.yaxis.set_ma jor_formatter(f ormatter)

ax.scatter( [3, 5, 70, 700, 900], [4, 8, 120, 160, 200], s=8, c='b',
marker='s', faceted=False)
ax.scatter( [1000, 2000, 3000, 4000, 5000], [2000, 4000, 6000, 8000,
1000], s=8, c='r', marker='s', faceted=False)

ax.set_xlim(1e-1, 1e5)
ax.set_ylim(1e-1, 1e5)
grid(True)
xlabel(r"Result ", fontsize = 12)
ylabel(r"Predic tion", fontsize = 12)

show()

Feb 28 '06 #7
>>>>> "Derek" == Derek Basch <db****@yahoo.c om> writes:

Derek> formatter = FuncFormatter(l og_10_product)
Derek> ax.xaxis.set_ma jor_formatter(f ormatter)
Derek> ax.yaxis.set_ma jor_formatter(f ormatter)

I would caution you against using identical objects for the x and y
axis *Locators*. For the formatters, it will do no harm, but for the
locators you can get screwed up because the locator object reads the
axis data and view limits when making it's choices.

Ie, do not do this:

ax.xaxis.set_ma jor_locator(loc ator)
ax.yaxis.set_ma jor_locator(loc ator)

but rather do this

ax.xaxis.set_ma jor_locator(MyL ocator())
ax.yaxis.set_ma jor_locator(Myl ocator())

Thanks for the example,
JDH
Mar 1 '06 #8
Good tip John. Hopefully it will help someone out. Thanks again.
Derek Basch

Mar 1 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2605
by: John Hunter | last post by:
matplotlib is a 2D plotting library for python. You can use matplotlib interactively from a python shell or IDE, or embed it in GUI applications (WX, GTK, and Tkinter). matplotlib supports many plot types: line plots, bar charts, log plots, images, pseudocolor plots, legends, date plots, finance charts and more. What's new since...
3
4037
by: Dr. Colombes | last post by:
On my home laptop computer, I'm trying to install the appropriate modules so that Python version 2.3.3 and IDLE version 1.0.2 (with an "import matplotlib.matlab" statement) can produce nice MatLab-like plots. I have a matplotlib.matlab-capable Python set-up running OK on my office desktop, which I obtained after downloading and installing...
0
4485
by: P Fu | last post by:
I am trying to plot pair using the XY scatter chart in Access and place it into a report. I want my x-axis to have "Age" values and the y-axis to have "Gross Area" values, both pulled using a query I created. Since the chart dialogue boxes only ask for the Y data series with an arbitrary X coordinate of 1, is there any way I can change...
3
3474
by: Joe | last post by:
This probably isn't the right group for this kind of question but I figured I would take a shot... I want to remove points that skew a scatter plot. For example 20 data points are around -75 to 100 on the Y axis but a couple of points are at 1500 and a couple at -500 How would I figure which points should be removed? Of course I want to...
1
4777
by: Martin Manns | last post by:
Hi, When I use matplotlib for a scatter plot with both dots and connecting lines, the exported eps file is huge, if the distances between many points are small. I think of this as a bug, since no preview tiff is included in the generated eps and a variety of text processing applications (including OpenOffice) crash when I try to import the...
0
1389
by: meggahertz | last post by:
I am using matplotlib to generate plot in python in linux. The porblem I am facing is that when I generate a plot using plot() then show() the script stops at that point until I close the plot manually by Alt+F4 or closing it with the mouse. Is there a way to make the script so that it keeps running and leaves the plot open? I I need help with...
1
5576
by: kjb034 | last post by:
I have the following macro. It works fine, creating an XY scatter plot in Excel 2003, but when one of my users runs it in Excel 2007, it creates a scatter plot with lines. Why does it do this? I am using "ChartType = xlXYScatter", not xlXYScatterLines. Public Sub CreateChart(ByVal viLabeledSeries As Integer, ByVal viNonLabeledSeries As...
2
3498
by: sharath067 | last post by:
I want to dynamically update the scatter plot based on the y-axis data received from a socket connection. I used python matplot lib in interactive mode to do this, but during dynamic updation if i move the window to a different location or minimize the window then the plot updation stops abruptly. Please let me know how to do this? I have...
1
6142
by: jpsheehan3366 | last post by:
I have a list of ordered pairs and I need to make a scatter plot in python. The scatter plot needs to appear in a second window. If necessary I could graph two lists versus each-other instead of a list of ordered pairs. Here is the program that I have so far. from visual import * from visual.graph import * import random import math ...
0
7698
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7673
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7970
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.