Getting started with bar charts

Hi Derek,

[Copying to matplotlib-users since an archive of this conversation could be helpful to others in the future.]

Re the other suggestions you have made. While I appreciate the
"forming hypothesis" approach is good when venturing into the
unknown, it does seem a little strange when dealing with a known
item e.g. software.

But it *is* unknown to the extent that the documentation is lacking! :slight_smile: Also, I think that the plot-customization possibilities of matplotlib are pretty nicely discoverable (once you know about getp/setp), and even if the pdf manual listed everything, it would be easier to use the introspective facilities than look things up in the manual.

In your example below, you go from line [21]
聽聽getp(recs[0])
to line[22]
聽聽setp(recs[0], 'facecolor')

Now, how did you know that there was 'facecolor' property that
could be set? How would one get a list of all these properties?

The list you want is precisely the output of the getp command. I elided the output since it is quite long, but I guess I didn't make it sufficiently clear.

The other issue is the colour:
colour=['red', 'green', 'blue'])
implies I would write:
colour=['125','125','250']

In hindsight, it was a bad idea on my part to make a barchart of three bars and color them precisely red, green, and blue... let's try again:

聽聽聽聽聽In [11]:bar(arange(10), cos(arange(10)), color=['blanchedalmond', 'darkorchid', 'gainsboro', 'honeydew', 'hotpink', 'khaki', 'lavenderblush', 'mintcream', 'peachpuff', 'lemonchiffon']);

So you can give a list of colors to make the bars different colors. (The color names are from matplotlib.colors.cnames.) If you want to make everything the same color, give just one color, not a list:

聽聽聽聽聽In [12]:figure(); bar([0,1], [3,1], color='lightcoral');

The syntax for shades of gray happens to be a string representing a number from 0 to 1:

聽聽聽聽聽In [13]:figure(); bar([0,1], [3,1], color='0.9');

If you want every bar to have the color with components 125, 125, 250 on a scale of 0..255, use hex notation:

聽聽聽聽聽In [14]:figure(); bar([0,1], [3,1], color='#7d7dfa');

路路路

On 21.8.2006, at 13.34, Derek Hohls wrote:

--
Jouni

Jouni

I have now loaded and tried to use iPython.

In some cases the xyz? command gives useful output -
in others, not.

So, if I have
聽聽ax = subplot(111)
Then ax? returns a number of get_ & set_ functions that
are available. So far, so good. But, if I try something
like :
聽聽In [9]: ax.set_xlim()?
I get
聽聽Object `ax.set_xlim()` not found.
So, I cannot find out more about what setxlim() is meant to
do, or how it works? What I did do was go and look at the
class documentation on-line, and this info is available there.

You suggested:
"The list you want is precisely the output of the getp command."
But for the getp? , I get:

Type: function
Base Class: <type 'function'>
String Form: <function getp at 0x00F67370>
Namespace: Interactive
File: c:\python24\lib\site-packages\matplotlib\artist.py
Definition: getp(o, *args)
Docstring:
聽聽聽聽Return the value of handle property s

h is an instance of a class, eg a Line2D or an Axes or Text.
if s is 'somename', this function returns
聽聽o.get_somename()
getp can be used to query all the gettable properties with getp(o)
Many properties have aliases for shorter typing, eg 'lw' is an
alias for 'linewidth'. In the output, aliases and full property
names will be listed as
聽聽property or alias = value
eg
聽聽linewidth or lw = 2
Example:
聽聽plot(t,s)
聽聽set(gca(), 'xlim', [0,10]) # set the x axis limits
or
聽聽plot(t,s)
聽聽a = gca()
聽聽a.set_xlim([0,10]) # does the same
聽聽
(and gca? returns something along the same lines)

Which does *not* intuitively lead me to something like:
聽聽xticklines = getp(gca(), 'xticklines')
for example??

So - the question is how to get to find the items I need
to set - amongst others, I am still looking for something to
size the tick marks; setting those on the bottom X-axis to
a specific size, while disabling those on the top X-axis.
The matplotlabprc file has a clearly labelled line that
addresses part of this:

xtick.major.size : 2 # major tick size in points

but of course I would like to do this in code. I am sort of
guessing this has something to do with the Tick class:
http://matplotlib.sourceforge.net/matplotlib.axis.html#Tick
but I cannot seem to work with Tick() ??

In addition, I cannot seem to see why some things work one way
and others - seemingly in the "same family" - do not. For example:
聽聽xticklabels = lab.getp(lab.gca(), 'xticklabels')
works just fine, and allows you set the font size, color etc for
the tick labels, whereas there is no:
聽聽lab.getp(lab.gca(), 'ylabel')
even though both appear to be dealing with a similar "thing" (a
Text object)??

路路路

***************

I guess that, overall, I have been expecting matplotlib to
have a simple "dot" notation throughout -
聽聽xaxis.xtick.major.size = 2
as this type of notation is readily easy to grasp and use,
but this preconception is blocking my grasp of how to use
the module 'as is'.

Again, apologies for the repetitive questions, and thanks for
patience in answering them.

Derek

Jouni K Sepp盲nen <jks@...397...> 2006/08/21 01:24 PM >>>

Hi Derek,

[Copying to matplotlib-users since an archive of this conversation
could be helpful to others in the future.]

On 21.8.2006, at 13.34, Derek Hohls wrote:

Re the other suggestions you have made. While I appreciate the
"forming hypothesis" approach is good when venturing into the
unknown, it does seem a little strange when dealing with a known
item e.g. software.

But it *is* unknown to the extent that the documentation is
lacking! :slight_smile: Also, I think that the plot-customization possibilities
of matplotlib are pretty nicely discoverable (once you know about
getp/setp), and even if the pdf manual listed everything, it would be
easier to use the introspective facilities than look things up in the
manual.

In your example below, you go from line [21]
聽聽getp(recs[0])
to line[22]
聽聽setp(recs[0], 'facecolor')

Now, how did you know that there was 'facecolor' property that
could be set? How would one get a list of all these properties?

The list you want is precisely the output of the getp command. I
elided the output since it is quite long, but I guess I didn't make
it sufficiently clear.

The other issue is the colour:
colour=['red', 'green', 'blue'])
implies I would write:
colour=['125','125','250']

In hindsight, it was a bad idea on my part to make a barchart of
three bars and color them precisely red, green, and blue... let's try
again:

聽聽聽聽聽In [11]:bar(arange(10), cos(arange(10)), color=
['blanchedalmond', 'darkorchid', 'gainsboro', 'honeydew', 'hotpink',
'khaki', 'lavenderblush', 'mintcream', 'peachpuff', 'lemonchiffon']);

So you can give a list of colors to make the bars different colors.
(The color names are from matplotlib.colors.cnames.) If you want to
make everything the same color, give just one color, not a list:

聽聽聽聽聽In [12]:figure(); bar([0,1], [3,1], color='lightcoral');

The syntax for shades of gray happens to be a string representing a
number from 0 to 1:

聽聽聽聽聽In [13]:figure(); bar([0,1], [3,1], color='0.9');

If you want every bar to have the color with components 125, 125, 250
on a scale of 0..255, use hex notation:

聽聽聽聽聽In [14]:figure(); bar([0,1], [3,1], color='#7d7dfa');

--
Jouni

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
This message is subject to the CSIR's copyright, terms and conditions and
e-mail legal notice. Views expressed herein do not necessarily represent the
views of the CSIR.

CSIR E-mail Legal Notice
http://mail.csir.co.za/CSIR_eMail_Legal_Notice.html

CSIR Copyright, Terms and Conditions
http://mail.csir.co.za/CSIR_Copyright.html

For electronic copies of the CSIR Copyright, Terms and Conditions and the CSIR
Legal Notice send a blank message with REQUEST LEGAL in the subject line to
CallCentre@...1230...

This message has been scanned for viruses and dangerous content by MailScanner,
and is believed to be clean.