I've only been able to plot data with both symbols and lines by
issuing two plot commands, one for markers and one for lines. That's
perfectly fine, but it creates a problem when I try to create a legend
for it. For some reason, the legend command by default alternates
between using symbols and lines, grabbing displaying the symbol from the
first plot command for the first series, then displaying a line type
from the second plot for the next series, etc.
This behavior is a bit strange, and in fact unacceptable when the
same line type is used for each series.
For instance, assume I plot four series using these markers: square,
circle, x and +, and then plotted a solid line to connect each series of
markers. The legend would describe the four series using: square, solid
line, x, solid line. Clearly, that wont' work.
I've been able get around this previously by issuing the legend
command right after the first plot command, before the second plot
command. In my current usage, though, I'm looping through a number of
files that are being plotted on the same graph. In this case, the fact
that I've plotted lines in the preceding loop causes the legend command
to revert to this alternating behavior.
Is there some way to explicitly define the symbols used by the legend
command? Or some way to plot lines with markers in the same command
which would presumably avoid this problem?
In general, plotting with matplotlib is so easy and intuitive that
I'm surprised to be having so much difficulty doing something as simple
as this. I'm sure I must be missing something obvious. The
documentation of the legend command was unenlightening.
Thanks,
J.S. 1 5206
>>>>> "Jorl" == Jorl Shefner <v4***@yahoo.com> writes:
Jorl> I've only been able to plot data with both symbols and
Jorl> lines by issuing two plot commands, one for markers and one
Jorl> for lines. That's perfectly fine, but it creates a problem
Jorl> when I try to create a legend for it. For some reason, the
Jorl> legend command by default alternates between using symbols
Jorl> and lines, grabbing displaying the symbol from the first
Jorl> plot command for the first series, then displaying a line
Jorl> type from the second plot for the next series, etc. This
Jorl> behavior is a bit strange, and in fact unacceptable when the
Jorl> same line type is used for each series.
Example code always helps, but note you can plot a line with lines and
markers like this
plot(x, y, '--s') # dashed line with square markers.
In this case matplotlib will recognize this as one line and should do
the legending properly.
However, if you do, which I infer you are from your post
plot(x, y, 's') # square markers.
plot(x, y, '--s') # square markers.
the plot will look the same but matplotlib considers this to be two
different lines and the legend will be messed up.
Note you can explicitly control what gets added to the legend, eg with
l1, l2 = plot(x, y, '--s', x1, y1, 'go')
p = bar(x3,y2)
legend((l1, p), ('My lines', 'My bars'))
In other words, if you don't like the way the autolegend is setup, you
can explicitly control the process.
Hope this helps.
JDH This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jorl Shefner |
last post by:
I have a problem that I run into a lot with the 'legend' command's
default behavior. I've found a work-around but I wonder if there's a
better way.
For a simple example, take the following:...
|
by: gurkesaft |
last post by:
Hello,
Does anyone know how to use scipy.plt? The documentation is wrong or
out of date at the scipy website, and I can't join their mailing lists
for some reason.
Most importantly, I need...
|
by: bwaha |
last post by:
Has anyone figured out how to get a legend for each line in a
matplotlib.collections.LineCollection instance?
No problem if I plot lines the default way ie. line,=plot(x,y). But I've had
to...
|
by: ehenlin |
last post by:
Hi,
How to make pylab work together with py2exe?
Have anyone managed to build a stand alone exe with pylab package?
I have made a small test script but that does not work.
setup.py...
|
by: spross |
last post by:
hi all
i have to use matplotlib on mac os x. on the official site of
matplotlib, i found a link to precompiled python packages for mac os x:
http://pythonmac.org/packages/py24-fat/index.html
...
|
by: dubing |
last post by:
Hi,
We have some html source like this:
<div class="survey">
<form action="students/cbe-graduate-students/survey.html"
method="post" id="frmPbSurvey">
<fieldset class="survey_item">...
|
by: vajratkarviraj |
last post by:
i hav python2.5, matplotlib0.90.1, and py2exe for python 2.5 all on windows xp... i hav a python program(letsc.py) which uses the matplotlib package... and i want 2 make an exe of it for distribution...
|
by: =?ISO-8859-1?Q?Fr=E9d=E9ric_Degraeve?= |
last post by:
Hi everybody,
I've got a problem concerning matplotlib/pylab. I use it to represent
curves. I will use these pictures in a report.
However, it writes me a string 'date' on the bottom of my x-axis....
|
by: PamMish1982 |
last post by:
Hi all,
I have recently started using Python and I am trying to make a GUI out of Tkinter. I am using matplotlib for the graphic purposes. I have to make a exe file from this code. I use py2exe...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |