Plot Shows Random Bar Graph and Wrong data value of each time in Ploty BAR Graph

The details of the issue is in the below path. I am sure this is not going to be plotly problem, however, I do not know the solution to this problem. The complete code is there in the below forum. How this can be corrected.

Issue :

  1. Every time the graph plot shows different data for the X-axis label which is not matching with the actual value(Random)

  2. Not all the X-axis label plotted, only 8-9 label graphs are plotted.We have 15 plus to plot.

solution to this problem will be of great help to progress on my task. Thank you in advance.

Hi @mbmarx,

I’m not sure I follow exactly what you’re trying to do, but I did spot one problem.

You compute the datalist, datalistFg, datalistRp arrays like this:


datalist = pd.read_table(r'D:\python\ython\xxx.tab',sep='\t')   #sep=\s+|\t+
datalistFg=pd.value_counts(datalist['Function group'].values, sort=True)
datalistRp=pd.value_counts(datalist['Responsible person'].values, sort=True)

and then use these as the x and y values of your go.Bar traces. The problem is that pd.value_counts will, in general, shorten the input Series (by removing duplicates) and sort the result by the unique values. This approach could cause datalist, datalistFg, and datalistRp to all have different lengths, and the ordering of datalistFg won’t necessarily line up with the ordering of datalistRp.

Hope that helps!
-Jon

I understood the problem and i am at last mile ,giving the modified code this plots all the Y axis value with reference to the X axis .Now it is perfectly fine.
Only one problem ,the X axis label is not coming ,what needs to be changed to get the X axis label here .If the X axis label is coming then everything will be alright.

what should be text=datalistFg, ? to get right X axis labels.

import pandas as pd
from io import StringIO
import requests
import pandas as pd
import numpy as np
from bs4 import BeautifulSoup
from nsepy import get_history

import plotly
plotly.__version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import plotly.graph_objs as go
init_notebook_mode(connected=True)
#import plotly.plotly as py

from datetime import date
from datetime import datetime

datalist = pd.read_table(r'D:\pml\1065025170_20180808062710.tab',sep='\t')   #sep=\s+|\t+
datalistFg=pd.value_counts(datalist['Function group'].values, sort=True)
datalistRp=pd.value_counts(datalist['Responsible person'].values, sort=True)
datalist1 = datalist.groupby('Function group').nunique()


#print(datalist1)

#graphing place
otrace1 =go.Bar(
    #x=stock_opt_pe.index
    x=datalist['Function group'].nunique(),
    y=datalist['Function group'].value_counts(),
    text=datalistFg,
    textposition = 'auto',
    #xaxis-type (enumerated: “-” | “linear” | “log” | “date” | “category” )
    #xaxis-type (enumerated: “-” | “linear” | “log” | “date” | “category” )
    #name='Function Group Vx RespPerson',
    #orientation = 'v',
    #marker = dict(
        #color = 'rgba(224, 224, 224, 0.6)',
        #line = dict(
            #color = 'rgba(246, 250, 206, 1.0)',
            #color = 'rgb(60, 60, 60)',
            #width = 0)
    #)
)

odata = [otrace1]
olayout = go.Layout(
    title = "TESTING",
    xaxis=dict(
    tickangle=35,
    showticklabels=True,
    type='category',
    title='Function group',
    tickmode='linear'),
    barmode="stack"
)
fig = dict(data=odata, layout=olayout)
#fig = dict(data=odata)
iplot(fig, filename = 'D:/python/test/Test-{}.html'.format("Testing"))
plot(fig,show_link = True, filename = 'D:/python/test/test_{}.html'.format("Testing"))

Hi @mbmarx,

Great! But I don’t think I quite understand your latest question. Are you talking about a single xaxis title? or the labels on the xaxis ticks?

Could you add a screen shot of what your figure looks like? Also, could you put your code in a fenced code block (https://help.github.com/articles/creating-and-highlighting-code-blocks/), this keeps the markdown renderer from messing up the formatting. It would also be helpful if you could include some sample data with the code so that it’s possible to copy and paste the whole example and run it.

-Jon

Hi Jon,
Thanks for helping me ,I have created another thread to get some help here

The code too slightly modified.

My requirement,
Y axis correctly shows the value (101 is the count of A1 it shows it correctly ) .
But in the X axis i want to print the series label as A1 ,SW1,AD1 IO1 etc or A1 / 101 SW1/70 like this .
it is printing 1,2 ,3 ,4 5 …25 i do not know how to get the right function group label here.

Here is the image of it and what i am looking for is also there in the image .

Hi Jon,
I have updated the image above .Can you please look into the python code and if any solution for it.

Hi @mbmarx,

To have text appear as the xaxis tick labels you need to make sure that you’re setting the bar.x value to an array of strings, rather than an array of numbers.

Does that help?

-Jon

If that is known the topic would not have come here at all. No solution yet .

try plotting x = df.functiongroup.value_counts().index and y=df.functiongroup.value_counts()

I have a similar issue. I used an array of strings for a grouped bar chart and it works fine as long as the dataset is not to large. So far I got it to work with a unique label set of 106 (one list has 101 and the other has 85) the moment I hit 107 unique values it acts the same way as @mbmarx reported. Is there a way to prevent it from switching to a numeric scaled x-axis and use the provided array?

Also, I tried to add the x value array as text (for the hover text for the bar) but it shows a number x label instead of the string label associated with that data set point.

Thanks.

Update.

So I created a data grid by combining my two sources and used this as the source of my grouped bar charts. This allowed me to increase the max size of unique x labels to 115 before it starts it renamed the labels to numbers and scaled them to fit.