[Matplotlib-users] Lien&bar combination graph.

Ravi Thakkar ravi.thakkar369 at gmail.com
Fri Mar 30 11:25:19 EDT 2018


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 <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. ;)
>
> 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
>> https://mail.python.org/mailman/listinfo/matplotlib-users
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180330/5913d5be/attachment-0001.html>


More information about the Matplotlib-users mailing list