Lien&bar combination graph.

Hi,
Guys, I am new to programming field, learning python to represent my
research data.
Anyone here please help me to get the x axis label and separate label on
both y axis. (as indicated in attached image).
Code is attached.

···

--
Ravi.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180329/ae69744a/attachment-0001.html>
-------------- next part --------------
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

width = 1 # width of a bar

m1_t = pd.DataFrame({
    'SD-0' :[246,211,212,85.3,131,370,124.3,115.8,135.3,145.2,104.3,59,42.4,55.8,20.2,13.9,5.15],
    'SD-15' :[236,176,169,126,152,86.8,98,212,164,131,91,77.9,18.5,30.5,21.4,6.3,13.5],
    '15':[715,1260,639,783,949,1032,1155,1343,1095,744,451,304,251,110,88.6,56.2,52.2],
    '0' :[530,1173,762,669.5,867,1018,1221,1203,1148,632,501,338,265,195,135,111,107]})
    
m1_t[['SD-0','SD-15']].plot(kind='bar', width = width)
m1_t['0'].plot(secondary_y=True,label='0 ppt',marker='o')
m1_t['15'].plot(secondary_y=True,label='15 ppt',marker='o')

ax = plt.gca()
plt.xlim([-width, len(m1_t['15'])-width])
ax.set_xticklabels(('0.25','0.5','1','2','4','6','8','12','24','48','96','144','192','288','336','432','528'))
ax.legend(loc='upper right', bbox_to_anchor=(1,0.85))

plt.title("Fish Study")
plt.ylabel("Concentration")
plt.xlabel("time")

plt.tight_layout()

plt.show()

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Figure_1.png
Type: image/png
Size: 47443 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180329/ae69744a/attachment-0001.png>

Hi Ravi,

You are using plotting capabilities wrapped by pandas, which hide a bit
the ?usual? objects used in the vanilla Matplotlib tutorials that you
could find :confused: (AFAICT).

Please find attach one way to get what you would like if I understood
correctly your wish. I personally tend to only use to object-oriented
interface but if you really prefer the pyplot interface ("plt.*"),
remember that the commands apply generally to the last active object,
which is relevant.

Hopefully this helps a bit.

Best,
Adrien

Hi,
Guys, I am new to programming field, learning python to represent my
research data.
Anyone here please help me to get the x axis label and separate label on
both y axis. (as indicated in attached image).
Code is attached.

--
Ravi.

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
Matplotlib-users Info Page

-------------- next part --------------
A non-text attachment was scrubbed...
Name: fish-study-graph_afv1.py
Type: text/x-python
Size: 1208 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180329/68ca413e/attachment.py&gt;

···

On 03/29/2018 10:05 AM, Ravi Thakkar wrote:

Ah, I didn?t notice that you were doing pandas plotting instead of matplotlib. This is ok: pandas plot takes an ax= keyword that lets you specify an axis on which to plot. You can then ignore the secondary_y nonsense which is unnecessary if you use the matplotlib object-oriented API. The code below works for me. (Apologies for the primary y label, as I don?t know what your quantities represent. :wink:

Note, the title and x label need to happen on the first axes you declare, which in this case is ax_bar. If I tried to add them to ax_line nothing happened.

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

width = 1 # width of a bar

m1_t = pd.DataFrame({
? ? 'SD-0' :[246,211,212,85.3,131,370,124.3,115.8,135.3,145.2,104.3,59,42.4,55.8,20.2,13.9,5.15],
? ? 'SD-15' :[236,176,169,126,152,86.8,98,212,164,131,91,77.9,18.5,30.5,21.4,6.3,13.5],
? ? '15':[715,1260,639,783,949,1032,1155,1343,1095,744,451,304,251,110,88.6,56.2,52.2],
? ? '0' :[530,1173,762,669.5,867,1018,1221,1203,1148,632,501,338,265,195,135,111,107]})

fig, ax_bar = plt.subplots()
ax_line = ax_bar.twinx()

m1_t[['SD-0','SD-15']].plot(kind='bar', width = width, ax=ax_bar)
m1_t['0'].plot(label='0 ppt',marker='o', ax=ax_line)
m1_t['15'].plot(label='15 ppt',marker='o', ax=ax_line)

ax_line.set_xlim(-width, m1_t.shape[0] + width)
ax_line.set_xticklabels(('0.25','0.5','1','2','4','6','8','12','24','48','96','144','192','288','336','432','528'))
ax_line.legend(loc='upper right', bbox_to_anchor=(1,0.85))

ax_line.set_ylabel("Concentration")
ax_bar.set_title("Fish Study")
ax_bar.set_xlabel("time")
ax_bar.set_ylabel("whatever")

plt.tight_layout()
plt.show()

···

On 29 Mar 2018, 6:46 PM -0400, Ravi Thakkar <ravi.thakkar369 at gmail.com>, wrote:

Hi Juan,
Thanks. I want to draw bar graph and its showing error. I dont have mathematically derived data on axis, I have straight forward observations.? ?I want to compare concentration of two different drug on by bar graph and another with two line graph. All in same graph. If you can suggest any example. TIA.

> On Thu, Mar 29, 2018 at 12:20 PM, Juan Nunez-Iglesias <jni.soma at gmail.com> wrote:
> > Hi Ravi, and welcome!
> >
> > I think this example does what you want?
> > https://matplotlib.org/examples/api/two_scales.html
> >
> > Juan.
> >
> > On 29 Mar 2018, 1:11 PM -0400, Ravi Thakkar <ravi.thakkar369 at gmail.com>, wrote:
> > > Hi,
> > > Guys, I am new to programming field, learning python to represent my research data.
> > > Anyone here please help me to get the x axis label and separate label on both y axis. (as indicated in attached image).
> > > Code is attached.
> > >
> > > --
> > > Ravi.
> > > _______________________________________________
> > > Matplotlib-users mailing list
> > > Matplotlib-users at python.org
> > > Matplotlib-users Info Page

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180330/cb50b405/attachment.html&gt;

Thanks Juan. Thanks a lot. :slight_smile:

With Thanks and Regards.

···

-------------------------------------------------------------------------
Ravindra Thakkar
Associate Scientist,
Kansas State University,
Manhattan, Kansas (USA)
-------------------------------------------------------------------------

On Fri, Mar 30, 2018 at 9:45 AM, Juan Nunez-Iglesias <jni.soma at gmail.com> wrote:

Ah, I didn?t notice that you were doing pandas plotting instead of
matplotlib. This is ok: pandas plot takes an ax= keyword that lets you
specify an axis on which to plot. You can then ignore the secondary_y
nonsense which is unnecessary if you use the matplotlib object-oriented
API. The code below works for me. (Apologies for the primary y label, as I
don?t know what your quantities represent. :wink:

Note, the title and x label need to happen on the first axes you declare,
which in this case is ax_bar. If I tried to add them to ax_line nothing
happened.

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

width = 1 # width of a bar

m1_t = pd.DataFrame({
    'SD-0' :[246,211,212,85.3,131,370,124.3,115.8,135.3,145.2,104.3,
59,42.4,55.8,20.2,13.9,5.15],
    'SD-15' :[236,176,169,126,152,86.8,98,212,164,131,91,77.9,18.5,30.5,
21.4,6.3,13.5],
    '15':[715,1260,639,783,949,1032,1155,1343,1095,744,451,
304,251,110,88.6,56.2,52.2],
    '0' :[530,1173,762,669.5,867,1018,1221,1203,1148,632,501,338,
265,195,135,111,107]})

fig, ax_bar = plt.subplots()
ax_line = ax_bar.twinx()

m1_t[['SD-0','SD-15']].plot(kind='bar', width = width, ax=ax_bar)
m1_t['0'].plot(label='0 ppt',marker='o', ax=ax_line)
m1_t['15'].plot(label='15 ppt',marker='o', ax=ax_line)

ax_line.set_xlim(-width, m1_t.shape[0] + width)
ax_line.set_xticklabels(('0.25','0.5','1','2','4','6','8',
'12','24','48','96','144','192','288','336','432','528'))
ax_line.legend(loc='upper right', bbox_to_anchor=(1,0.85))

ax_line.set_ylabel("Concentration")
ax_bar.set_title("Fish Study")
ax_bar.set_xlabel("time")
ax_bar.set_ylabel("whatever")

plt.tight_layout()
plt.show()

On 29 Mar 2018, 6:46 PM -0400, Ravi Thakkar <ravi.thakkar369 at gmail.com>, > wrote:

Hi Juan,
Thanks. I want to draw bar graph and its showing error. I dont have
mathematically derived data on axis, I have straight forward observations.
I want to compare concentration of two different drug on by bar graph and
another with two line graph. All in same graph. If you can suggest any
example. TIA.

On Thu, Mar 29, 2018 at 12:20 PM, Juan Nunez-Iglesias <jni.soma at gmail.com> > wrote:

Hi Ravi, and welcome!

I think this example does what you want?
https://matplotlib.org/examples/api/two_scales.html

Juan.

On 29 Mar 2018, 1:11 PM -0400, Ravi Thakkar <ravi.thakkar369 at gmail.com>, >> wrote:

Hi,
Guys, I am new to programming field, learning python to represent my
research data.
Anyone here please help me to get the x axis label and separate label on
both y axis. (as indicated in attached image).
Code is attached.

--
Ravi.
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
Matplotlib-users Info Page

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180330/5913d5be/attachment-0001.html&gt;

No prob, and thank you for providing a simple runnable example ? that?s gold when asking for help. =)

···

On 30 Mar 2018, 11:25 AM -0400, Ravi Thakkar <ravi.thakkar369 at gmail.com>, wrote:

Thanks Juan. Thanks a lot. :slight_smile:

With Thanks and Regards.
-------------------------------------------------------------------------
Ravindra Thakkar
Associate Scientist,
Kansas State?University,
Manhattan, Kansas (USA)
-------------------------------------------------------------------------

> On Fri, Mar 30, 2018 at 9:45 AM, Juan Nunez-Iglesias <jni.soma at gmail.com> wrote:
> > Ah, I didn?t notice that you were doing pandas plotting instead of matplotlib. This is ok: pandas plot takes an ax= keyword that lets you specify an axis on which to plot. You can then ignore the secondary_y nonsense which is unnecessary if you use the matplotlib object-oriented API. The code below works for me. (Apologies for the primary y label, as I don?t know what your quantities represent. :wink:
> >
> > Note, the title and x label need to happen on the first axes you declare, which in this case is ax_bar. If I tried to add them to ax_line nothing happened.
> >
> > import matplotlib.pyplot as plt
> > import numpy as np
> > import pandas as pd
> >
> > width = 1 # width of a bar
> >
> > m1_t = pd.DataFrame({
> > ? ? 'SD-0' :[246,211,212,85.3,131,370,124.3,115.8,135.3,145.2,104.3,59,42.4,55.8,20.2,13.9,5.15],
> > ? ? 'SD-15' :[236,176,169,126,152,86.8,98,212,164,131,91,77.9,18.5,30.5,21.4,6.3,13.5],
> > ? ? '15':[715,1260,639,783,949,1032,1155,1343,1095,744,451,304,251,110,88.6,56.2,52.2],
> > ? ? '0' :[530,1173,762,669.5,867,1018,1221,1203,1148,632,501,338,265,195,135,111,107]})
> >
> > fig, ax_bar = plt.subplots()
> > ax_line = ax_bar.twinx()
> >
> > m1_t[['SD-0','SD-15']].plot(kind='bar', width = width, ax=ax_bar)
> > m1_t['0'].plot(label='0 ppt',marker='o', ax=ax_line)
> > m1_t['15'].plot(label='15 ppt',marker='o', ax=ax_line)
> >
> > ax_line.set_xlim(-width, m1_t.shape[0] + width)
> > ax_line.set_xticklabels(('0.25','0.5','1','2','4','6','8','12','24','48','96','144','192','288','336','432','528'))
> > ax_line.legend(loc='upper right', bbox_to_anchor=(1,0.85))
> >
> > ax_line.set_ylabel("Concentration")
> > ax_bar.set_title("Fish Study")
> > ax_bar.set_xlabel("time")
> > ax_bar.set_ylabel("whatever")
> >
> > plt.tight_layout()
> > plt.show()
> >
> >
> > On 29 Mar 2018, 6:46 PM -0400, Ravi Thakkar <ravi.thakkar369 at gmail.com>, wrote:
> > > Hi Juan,
> > > Thanks. I want to draw bar graph and its showing error. I dont have mathematically derived data on axis, I have straight forward observations.? ?I want to compare concentration of two different drug on by bar graph and another with two line graph. All in same graph. If you can suggest any example. TIA.
> > >
> > >
> > > > On Thu, Mar 29, 2018 at 12:20 PM, Juan Nunez-Iglesias <jni.soma at gmail.com> wrote:
> > > > > Hi Ravi, and welcome!
> > > > >
> > > > > I think this example does what you want?
> > > > > https://matplotlib.org/examples/api/two_scales.html
> > > > >
> > > > > Juan.
> > > > >
> > > > > On 29 Mar 2018, 1:11 PM -0400, Ravi Thakkar <ravi.thakkar369 at gmail.com>, wrote:
> > > > > > Hi,
> > > > > > Guys, I am new to programming field, learning python to represent my research data.
> > > > > > Anyone here please help me to get the x axis label and separate label on both y axis. (as indicated in attached image).
> > > > > > Code is attached.
> > > > > >
> > > > > > --
> > > > > > Ravi.
> > > > > > _______________________________________________
> > > > > > Matplotlib-users mailing list
> > > > > > Matplotlib-users at python.org
> > > > > > Matplotlib-users Info Page
> > >

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180330/4656c6aa/attachment.html&gt;