Yaxis scale, plotly

I want to plot histogram, however, there is problem for yaxis scale. This is the first time I use plotly

Hi,

If you expect a helpful answer you will need to explain more precisely what you aim to achieve. By the looks of it, I am not sure if you want to make a histogram or bar chart. The best would be to provide the source code.

Some docs about bar charts and histograms:

I am sorry for the confusion. I am trying to plot a histogram. Which can plot for positive and negative words. It is like a sentiment analysis. I am reading multiple text file, from the text file, there is some functions that i made to count the positive and negative words. But for now, i only want to read for only one text file, the problem now is the scale of the y axis. image
image
i is the array from previous function.

def count(i, positive, negative):
sentim = [“Positive”]
sentim2=[“Negative”]
val = []
val2 = []
totalP = 0
totalN = 0
for k in i:
totalP +=positive
totalN+=negative
val.append(totalP)
val2.append(totalN)
print(totalP)
print(totalN)
data = [
go.Histogram(
x=sentim,
y=val,
name= “Positive”,
marker = dict(
color=’#000000’
)
),

    go.Histogram(
        x=sentim2,
        y=val2,
        name= "Negative",
        marker=dict(
            color='#EB89B5'
        )
    )
]
layout = go.Layout(
    yaxis = dict(autorange=True),
    bargap = 0,
    bargroupgap = 0,
    width = 200
    )
fig = go.Figure(data=data, layout=layout)
py.plot(fig, filename='Histogram')

Hi @aqiff12, welcome to the forums!

To make it easier for folks to help you out, please put your code in a fenced code black (See https://help.github.com/en/articles/creating-and-highlighting-code-blocks) and include your python imports so that it’s possible for others to copy and paste the code black and run it.

As a general comment, if you are computing the counts of “positive” and “negative” words yourself, then you’ll want to use a bar trace type. The histogram trace type is used if you want plotly to perform the aggregation (counts) for you.

-Jon

huh I don’t really understand,


the first picture is what I get, then the second is what I wanted but ! i only get the second one after I changed it manually in the editor of plotly. I use lots of import, and there will be lots text file if I want to put my code here.

def count(i, positive, negative, posArr, negArr):
    totalP = 0
    totalN = 0
    totalP += positive
    totalN += negative
    posArr.append(totalP)
    negArr.append(totalN)
    print(posArr)
    print(negArr)

    pos = go.Histogram(opacity = 0.75,x=posArr)

    neg = go.Histogram(opacity=0.75,x=negArr)

    data=[pos,neg]

    layout = go.Layout(barmode="overlay")

    fig = go.Figure(data=data, layout=layout)
    py.plot(fig, filename='Overlaid Histogram', auto_open=True)

Hi @aqiff12,

Try replacing go.Histogram with go.Bar. For the bar trace, I think you’ll need to change opacity=0.75 to marker=dict(opacity=0.75).

-Jon