Graph

Hi all,

I ploted a graph and above this graph I plot another graph about data errors.
so, the x-axis scale according with data errors only goes on 1.4, but I would like to display up to 1.5. how I do that?
I also want to increase the space between 0.0 - 0.2, 0.2 - 0.4, so on so that points can be better visualized.

My image attached

Thanks,
Waleria

graph.png

To set the x limits:
ax.set_xlim([0.0, 1.5])

To increase the space between 0.0-0.2 and 0.2-0.4, you might want to consider log scale (although zero values will cause problems)?
ax.set_xscale(‘log’)

Ben Root

···

On Wed, Oct 6, 2010 at 12:13 PM, Waléria Antunes David <waleriantunes@…287…> wrote:

Hi all,

I ploted a graph and above this graph I plot another graph about data errors.
so, the x-axis scale according with data errors only goes on 1.4, but I would like to display up to 1.5. how I do that?

I also want to increase the space between 0.0 - 0.2, 0.2 - 0.4, so on so that points can be better visualized.

My image attached

Thanks,
Waleria

the x-axis scale according with data errors only goes on 1.4, but I would like to display up to 1.5. how I do that?

http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.xlim

I also want to increase the space between 0.0 - 0.2, 0.2 - 0.4, so on so that points can be better visualized.

Change the figsize:
http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.figure

hth,
Alan Isaac

···

On 10/6/2010 1:13 PM, Waléria Antunes David wrote:

2010/10/6 Waléria Antunes David <waleriantunes@...287...>:

I ploted a graph and above this graph I plot another graph about data
errors.

You can do this in one step by using ax.errorbar()
http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes.errorbar
.

Try using fmt=',', this will plot pixels as the markers.

Friedrich

Benjamin,

I used the ‘ax.set_xscale (’ log ‘)’, but the points were even more confused. What I need is to increase from 0.0 to 0.2 points, 0.2 to 0.4 … increase the size of the graph. However I do not know if the chart is well visualized on a monitor 20’’.?

And how do I let my chart like this: http://www.supernova.lbl.gov/PDFs/SCP2003SNeCMBClust.pdf
This graph format with vertical line on, something like that.

Thanks,

graph1.png

···

On Wed, Oct 6, 2010 at 2:24 PM, Benjamin Root <ben.root@…1304…> wrote:

On Wed, Oct 6, 2010 at 12:13 PM, Waléria Antunes David <waleriantunes@…287…> wrote:

Hi all,

I ploted a graph and above this graph I plot another graph about data errors.
so, the x-axis scale according with data errors only goes on 1.4, but I would like to display up to 1.5. how I do that?

I also want to increase the space between 0.0 - 0.2, 0.2 - 0.4, so on so that points can be better visualized.

My image attached

Thanks,
Waleria

To set the x limits:
ax.set_xlim([0.0, 1.5])

To increase the space between 0.0-0.2 and 0.2-0.4, you might want to consider log scale (although zero values will cause problems)?

ax.set_xscale(‘log’)

Ben Root

Benjamin,

I used the ‘ax.set_xscale (’ log ‘)’, but the points were even more confused. What I need is to increase from 0.0 to 0.2 points, 0.2 to 0.4 … increase the size of the graph. However I do not know if the chart is well visualized on a monitor 20’’.?

Are you trying to increase the spacing in the x direction or the y direction? Log scaling is a standard trick to achieve this effect.

And how do I let my chart like this: http://www.supernova.lbl.gov/PDFs/SCP2003SNeCMBClust.pdf
This graph format with vertical line on, something like that.

Are you asking how to add a vertical line to your graph, or how to have only the vertical grid lines?

Ben Root

···

On Wed, Oct 6, 2010 at 2:36 PM, Waléria Antunes David <waleriantunes@…287…> wrote:

How to have only the vertical grid lines.?
And I trying to increase the spacing in the x direction, I used the ‘ax.set_xscale (’ log ‘)’, but the points were even more confused. Do you saw my image that sent yestarday?

···

On Wed, Oct 6, 2010 at 5:10 PM, Benjamin Root <ben.root@…83…1304…> wrote:

On Wed, Oct 6, 2010 at 2:36 PM, Waléria Antunes David <waleriantunes@…287…> wrote:

Benjamin,

I used the ‘ax.set_xscale (’ log ‘)’, but the points were even more confused. What I need is to increase from 0.0 to 0.2 points, 0.2 to 0.4 … increase the size of the graph. However I do not know if the chart is well visualized on a monitor 20’’.?

Are you trying to increase the spacing in the x direction or the y direction? Log scaling is a standard trick to achieve this effect.

And how do I let my chart like this: http://www.supernova.lbl.gov/PDFs/SCP2003SNeCMBClust.pdf
This graph format with vertical line on, something like that.

Are you asking how to add a vertical line to your graph, or how to have only the vertical grid lines?

Ben Root

Hi,

I’m asking how to have only the vertical grid lines.?
And I’m trying to increase the spacing in the x direction, I used the ‘ax.set_xscale (’ log ‘)’, but the points were even more confused.
Do you saw my image that sent yestarday?

Thanks,
Waleria

···

On Wed, Oct 6, 2010 at 5:10 PM, Benjamin Root <ben.root@…1304…> wrote:

On Wed, Oct 6, 2010 at 2:36 PM, Waléria Antunes David <waleriantunes@…287…> wrote:

Benjamin,

I used the ‘ax.set_xscale (’ log ‘)’, but the points were even more confused. What I need is to increase from 0.0 to 0.2 points, 0.2 to 0.4 … increase the size of the graph. However I do not know if the chart is well visualized on a monitor 20’’.?

Are you trying to increase the spacing in the x direction or the y direction? Log scaling is a standard trick to achieve this effect.

And how do I let my chart like this: http://www.supernova.lbl.gov/PDFs/SCP2003SNeCMBClust.pdf
This graph format with vertical line on, something like that.

Are you asking how to add a vertical line to your graph, or how to have only the vertical grid lines?

Ben Root

Hi,

I’m asking how to have only the vertical grid lines.?
And I’m trying to increase the spacing in the x direction, I used the ‘ax.set_xscale (’ log ‘)’, but the points were even more confused.
Do you saw my image that sent yestarday?

Thanks,
Waleria

I have to agree with Ben that your description is a little confusing. Looking at the plot you posted, I’m not sure what part of the plot you’re interested in reproducing. I don’t see any “vertical lines”; do you mean the vertical layout of the plot itself? If that’s the case you can set the figure size such that it is taller than it is wide. For example, before creating your plot you can call:

import matplotlib.pyplot as plt

plt.figure(figsize=(6, 8))

But from your original question, it sounds like you want the opposite, since a wider plot would stretch the x-distance between data points (logspacing stretches distances for low values, but maybe you want to stretch the distance for all values?). In this case you could just increase the width of the figure; for example:

plt.figure(figsize=(12, 6))

This may not fit on your screen, though. If you’re working interactively (with plt.show instead of plt.savefig) you can just resize the window to your liking.

-T

···

On Oct 7, 2010, at 11:54 AM, Waléria Antunes David wrote:

On Wed, Oct 6, 2010 at 5:10 PM, Benjamin Root <ben.root@…1304…> wrote:

On Wed, Oct 6, 2010 at 2:36 PM, Waléria Antunes David <waleriantunes@…287…> wrote:

Benjamin,

I used the ‘ax.set_xscale (’ log ‘)’, but the points were even more confused. What I need is to increase from 0.0 to 0.2 points, 0.2 to 0.4 … increase the size of the graph. However I do not know if the chart is well visualized on a monitor 20’’.?

Are you trying to increase the spacing in the x direction or the y direction? Log scaling is a standard trick to achieve this effect.

And how do I let my chart like this: http://www.supernova.lbl.gov/PDFs/SCP2003SNeCMBClust.pdf
This graph format with vertical line on, something like that.

Are you asking how to add a vertical line to your graph, or how to have only the vertical grid lines?

Ben Root


Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3.
Spend less time writing and rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@…642…ts.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

I need to know how do these vertical lines on the graph. See the picture, the lines circled.

Thanks,
Waleria

lines_graph.jpg

···

On Thu, Oct 7, 2010 at 2:32 PM, Tony S Yu <tsyu80@…287…> wrote:

On Oct 7, 2010, at 11:54 AM, Waléria Antunes David wrote:

Hi,

I’m asking how to have only the vertical grid lines.?
And I’m trying to increase the spacing in the x direction, I used the ‘ax.set_xscale (’ log ‘)’, but the points were even more confused.
Do you saw my image that sent yestarday?

Thanks,
Waleria

I have to agree with Ben that your description is a little confusing. Looking at the plot you posted, I’m not sure what part of the plot you’re interested in reproducing. I don’t see any “vertical lines”; do you mean the vertical layout of the plot itself? If that’s the case you can set the figure size such that it is taller than it is wide. For example, before creating your plot you can call:

import matplotlib.pyplot as plt

plt.figure(figsize=(6, 8))

But from your original question, it sounds like you want the opposite, since a wider plot would stretch the x-distance between data points (logspacing stretches distances for low values, but maybe you want to stretch the distance for all values?). In this case you could just increase the width of the figure; for example:

plt.figure(figsize=(12, 6))

This may not fit on your screen, though. If you’re working interactively (with plt.show instead of plt.savefig) you can just resize the window to your liking.

-T

On Wed, Oct 6, 2010 at 5:10 PM, Benjamin Root <ben.root@…1304…> wrote:

On Wed, Oct 6, 2010 at 2:36 PM, Waléria Antunes David <waleriantunes@…287…> wrote:

Benjamin,

I used the ‘ax.set_xscale (’ log ‘)’, but the points were even more confused. What I need is to increase from 0.0 to 0.2 points, 0.2 to 0.4 … increase the size of the graph. However I do not know if the chart is well visualized on a monitor 20’’.?

Are you trying to increase the spacing in the x direction or the y direction? Log scaling is a standard trick to achieve this effect.

And how do I let my chart like this: http://www.supernova.lbl.gov/PDFs/SCP2003SNeCMBClust.pdf
This graph format with vertical line on, something like that.

Are you asking how to add a vertical line to your graph, or how to have only the vertical grid lines?

Ben Root


Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3.

Spend less time writing and rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb_______________________________________________

Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

We call these major and minor ticks. The major ticks are the taller
ones, the minor ticks are the smaller ones. Their location is
controlled by the major and minor Locator instances, and the text
printed beside them is controlled by the major and minor formatter.

See

  http://matplotlib.sourceforge.net/examples/pylab_examples/major_minor_demo1.html
  http://matplotlib.sourceforge.net/examples/pylab_examples/major_minor_demo2.html

and

  http://matplotlib.sourceforge.net/search.html?q=codex+set_minor_locator

To control the tick properties themselves, see the Tick section in

  http://matplotlib.sourceforge.net/users/artists.html

JDH

···

On Thu, Oct 7, 2010 at 1:01 PM, Waléria Antunes David <waleriantunes@...287...> wrote:

I need to know how do these vertical lines on the graph. See the picture,
the lines circled.

Hi,

I did like the links below, but seeing as it was my chart.

See

My code: http://pastebin.com/KcjHAPLN

graph.png

···

On Thu, Oct 7, 2010 at 3:08 PM, John Hunter <jdh2358@…287…> wrote:

On Thu, Oct 7, 2010 at 1:01 PM, Waléria Antunes David > > <waleriantunes@…287…> wrote:

I need to know how do these vertical lines on the graph. See the picture,

the lines circled.

We call these major and minor ticks. The major ticks are the taller

ones, the minor ticks are the smaller ones. Their location is

controlled by the major and minor Locator instances, and the text

printed beside them is controlled by the major and minor formatter.

See

http://matplotlib.sourceforge.net/examples/pylab_examples/major_minor_demo1.html

http://matplotlib.sourceforge.net/examples/pylab_examples/major_minor_demo2.html

and

http://matplotlib.sourceforge.net/search.html?q=codex+set_minor_locator

To control the tick properties themselves, see the Tick section in

http://matplotlib.sourceforge.net/users/artists.html

JDH

As John mentioned, the major and minor ticks were the taller and shorter ticks, respectively. In your pasted example, you only change the minor ticks; by setting the majorLocator to same value as in the original example (i.e. 20), you only get the major tick at 0 because your data only goes to 1.5 (i.e. 20 is outside your plot range).

Also, the majorFormatter in the example is set to work with integers, but your major tick labels should be float values (since most of them are between 0 and 1). Thus, the majorFormatter code is unnecessary (commented out below).

Finally, a pet peeve: when posting example code, please make the effort to generate data for the plot so that others can easily run the code (see attached).

-Tony

···

On Oct 7, 2010, at 3:38 PM, Waléria Antunes David wrote:

Hi,

I did like the links below, but seeing as it was my chart.

See

My code: http://pastebin.com/KcjHAPLN

On Thu, Oct 7, 2010 at 3:08 PM, John Hunter <jdh2358@…287…> wrote:

On Thu, Oct 7, 2010 at 1:01 PM, Waléria Antunes David > > > > <waleriantunes@…287…> wrote:

I need to know how do these vertical lines on the graph. See the picture,

the lines circled.

We call these major and minor ticks. The major ticks are the taller

ones, the minor ticks are the smaller ones. Their location is

controlled by the major and minor Locator instances, and the text

printed beside them is controlled by the major and minor formatter.

See

http://matplotlib.sourceforge.net/examples/pylab_examples/major_minor_demo1.html

http://matplotlib.sourceforge.net/examples/pylab_examples/major_minor_demo2.html

and

http://matplotlib.sourceforge.net/search.html?q=codex+set_minor_locator

To control the tick properties themselves, see the Tick section in

http://matplotlib.sourceforge.net/users/artists.html

JDH

<graph.png>

#—

import numpy as np

import matplotlib.pyplot as plt

from matplotlib.ticker import MultipleLocator, FormatStrFormatter

def gera_grafico(N=200, eps=1):

x = np.abs(np.random.randn(N))

y = 10np.log((30x + 1.)**(0.5)) + 34 + eps * np.random.randn(N)

yerr = eps * np.random.randn(N)

majorLocator = MultipleLocator(0.2)

majorFormatter = FormatStrFormatter(’%d’)

minorLocator = MultipleLocator(0.02)

fig, ax = plt.subplots()

plt.errorbar(x, y, yerr, fmt=‘ob’, label=‘date’)

plt.xlim(0.0, 1.5)

#plt.xscale(‘log’)

#grid(True)

ax.xaxis.set_major_locator(majorLocator)

ax.xaxis.set_major_formatter(majorFormatter)

ax.xaxis.set_minor_locator(minorLocator)

return fig

if name == ‘main’:

gera_grafico()

plt.show()

I don’t understand what you did, i’m reading error data from a file.

def gera_grafico(N=200, eps=1):

x = np.abs(np.random.randn(N))

y = 10np.log((30x + 1.)**(0.5)) + 34 + eps * np.random.randn(N)

yerr = eps * np.random.randn(N)

I don’t understand what you did in this code

??

Thanks,
Waleria.

···

On Thu, Oct 7, 2010 at 5:06 PM, Tony S Yu <tsyu80@…985…> wrote:

On Oct 7, 2010, at 3:38 PM, Waléria Antunes David wrote:

Hi,

I did like the links below, but seeing as it was my chart.

See

My code: http://pastebin.com/KcjHAPLN

On Thu, Oct 7, 2010 at 3:08 PM, John Hunter <jdh2358@…287…> wrote:

On Thu, Oct 7, 2010 at 1:01 PM, Waléria Antunes David > > > > > > <waleriantunes@…287…> wrote:

I need to know how do these vertical lines on the graph. See the picture,

the lines circled.

We call these major and minor ticks. The major ticks are the taller

ones, the minor ticks are the smaller ones. Their location is

controlled by the major and minor Locator instances, and the text

printed beside them is controlled by the major and minor formatter.

See

http://matplotlib.sourceforge.net/examples/pylab_examples/major_minor_demo1.html

http://matplotlib.sourceforge.net/examples/pylab_examples/major_minor_demo2.html

and

http://matplotlib.sourceforge.net/search.html?q=codex+set_minor_locator

To control the tick properties themselves, see the Tick section in

http://matplotlib.sourceforge.net/users/artists.html

JDH

<graph.png>

As John mentioned, the major and minor ticks were the taller and shorter ticks, respectively. In your pasted example, you only change the minor ticks; by setting the majorLocator to same value as in the original example (i.e. 20), you only get the major tick at 0 because your data only goes to 1.5 (i.e. 20 is outside your plot range).

Also, the majorFormatter in the example is set to work with integers, but your major tick labels should be float values (since most of them are between 0 and 1). Thus, the majorFormatter code is unnecessary (commented out below).

Finally, a pet peeve: when posting example code, please make the effort to generate data for the plot so that others can easily run the code (see attached).

-Tony

#—

import numpy as np

import matplotlib.pyplot as plt

from matplotlib.ticker import MultipleLocator, FormatStrFormatter

def gera_grafico(N=200, eps=1):

x = np.abs(np.random.randn(N))

y = 10np.log((30x + 1.)**(0.5)) + 34 + eps * np.random.randn(N)

yerr = eps * np.random.randn(N)

majorLocator = MultipleLocator(0.2)

majorFormatter = FormatStrFormatter(’%d’)

minorLocator = MultipleLocator(0.02)

fig, ax = plt.subplots()

plt.errorbar(x, y, yerr, fmt=‘ob’, label=‘date’)

plt.xlim(0.0, 1.5)

#plt.xscale(‘log’)

#grid(True)

ax.xaxis.set_major_locator(majorLocator)

ax.xaxis.set_major_formatter(majorFormatter)

ax.xaxis.set_minor_locator(minorLocator)

return fig

if name == ‘main’:

gera_grafico()

plt.show()

I don’t understand what you did, i’m reading error data from a file.

def gera_grafico(N=200, eps=1):

x = np.abs(np.random.randn(N))

y = 10np.log((30x + 1.)**(0.5)) + 34 + eps * np.random.randn(N)

yerr = eps * np.random.randn(N)

I don’t understand what you did in this code

??

Thanks,
Waleria.

Hey Waleria,

That was just some code to make up fake data with roughly the same shape and range as the data you plotted. As I mentioned, I needed to put something there to run your code.

Where do you get an error? If it’s from the code above, you can just replace it with your data. In any case, you don’t need to use the code I pasted; just make the changes I suggested: Fix the number passed to majorLocator and remove (or fix the initialization of) majorFormatter.

-T

···

On Oct 8, 2010, at 6:52 AM, Waléria Antunes David wrote:

On Thu, Oct 7, 2010 at 5:06 PM, Tony S Yu <tsyu80@…287…> wrote:

On Oct 7, 2010, at 3:38 PM, Waléria Antunes David wrote:

Hi,

I did like the links below, but seeing as it was my chart.

See

My code: http://pastebin.com/KcjHAPLN

On Thu, Oct 7, 2010 at 3:08 PM, John Hunter <jdh2358@…287…> wrote:

On Thu, Oct 7, 2010 at 1:01 PM, Waléria Antunes David > > > > > > > > <waleriantunes@…287…> wrote:

I need to know how do these vertical lines on the graph. See the picture,

the lines circled.

We call these major and minor ticks. The major ticks are the taller

ones, the minor ticks are the smaller ones. Their location is

controlled by the major and minor Locator instances, and the text

printed beside them is controlled by the major and minor formatter.

See

http://matplotlib.sourceforge.net/examples/pylab_examples/major_minor_demo1.html

http://matplotlib.sourceforge.net/examples/pylab_examples/major_minor_demo2.html

and

http://matplotlib.sourceforge.net/search.html?q=codex+set_minor_locator

To control the tick properties themselves, see the Tick section in

http://matplotlib.sourceforge.net/users/artists.html

JDH

<graph.png>

As John mentioned, the major and minor ticks were the taller and shorter ticks, respectively. In your pasted example, you only change the minor ticks; by setting the majorLocator to same value as in the original example (i.e. 20), you only get the major tick at 0 because your data only goes to 1.5 (i.e. 20 is outside your plot range).

Also, the majorFormatter in the example is set to work with integers, but your major tick labels should be float values (since most of them are between 0 and 1). Thus, the majorFormatter code is unnecessary (commented out below).

Finally, a pet peeve: when posting example code, please make the effort to generate data for the plot so that others can easily run the code (see attached).

-Tony

#—

import numpy as np

import matplotlib.pyplot as plt

from matplotlib.ticker import MultipleLocator, FormatStrFormatter

def gera_grafico(N=200, eps=1):

x = np.abs(np.random.randn(N))

y = 10np.log((30x + 1.)**(0.5)) + 34 + eps * np.random.randn(N)

yerr = eps * np.random.randn(N)

majorLocator = MultipleLocator(0.2)

majorFormatter = FormatStrFormatter(’%d’)

minorLocator = MultipleLocator(0.02)

fig, ax = plt.subplots()

plt.errorbar(x, y, yerr, fmt=‘ob’, label=‘date’)

plt.xlim(0.0, 1.5)

#plt.xscale(‘log’)

#grid(True)

ax.xaxis.set_major_locator(majorLocator)

ax.xaxis.set_major_formatter(majorFormatter)

ax.xaxis.set_minor_locator(minorLocator)

return fig

if name == ‘main’:

gera_grafico()

plt.show()