Lien&bar combination graph.

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Lien&bar combination graph.

Ravi Thakkar
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
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

Fish-study-graph.py (1K) Download Attachment
Figure_1.png (63K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Lien&bar combination graph.

vincent.adrien@gmail.com
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 :/ (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

On 03/29/2018 10:05 AM, Ravi Thakkar 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
> [hidden email]
> https://mail.python.org/mailman/listinfo/matplotlib-users
>

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

fish-study-graph_afv1.py (1K) Download Attachment
jni
Reply | Threaded
Open this post in threaded view
|

Re: Lien&bar combination graph.

jni
In reply to this post by Ravi Thakkar
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. ;)

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 <[hidden email]>, 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 <[hidden email]> wrote:
Hi Ravi, and welcome!

I think this example does what you want?

Juan.

On 29 Mar 2018, 1:11 PM -0400, Ravi Thakkar <[hidden email]>, 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
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Lien&bar combination graph.

Ravi Thakkar
Thanks Juan. Thanks a lot. :) 

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 <[hidden email]> 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. ;)

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 <[hidden email]>, 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 <[hidden email]> wrote:
Hi Ravi, and welcome!

I think this example does what you want?

Juan.

On 29 Mar 2018, 1:11 PM -0400, Ravi Thakkar <[hidden email]>, 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
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users



_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
jni
Reply | Threaded
Open this post in threaded view
|

Re: Lien&bar combination graph.

jni
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 <[hidden email]>, wrote:
Thanks Juan. Thanks a lot. :) 

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 <[hidden email]> 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. ;)

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 <[hidden email]>, 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 <[hidden email]> wrote:
Hi Ravi, and welcome!

I think this example does what you want?

Juan.

On 29 Mar 2018, 1:11 PM -0400, Ravi Thakkar <[hidden email]>, 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
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users



_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users