Python CGI script to show Google scatter chart with known trendline - google-visualization

I am trying to make a Python CGI script show a Google ScatterChart with a linear trendline whose equation I can use elsewhere. The ScatterChart trendline option draws a trendline and I can find out the equation of the line by putting my pointer over the trendline, but that's no help because I need to get the coeffients from the equation programatically.
One solution I can think of is to write a function that computes the trendline and displays it on top of the ScatterChart. The problem here is that I don't know how to make a Google chart that has two series of data plotted differently (one series as dots, the other as a line).
A hybrid solution would be to use my function to compute the trendline so that I have the equation in my program, and then display the chart with its own Google-generated trendline. The issue here is that I know there is more than one way to make a linear trendline and I don't know which way Google uses.

Use the series..lineWidth option to make one series draw with a connecting line:
series: {
0: {
// scatter series
lineWidth: 0
},
1: {
// trendline
lineWidth: 1,
// control the point size of the trendline
pointSize: 0,
// set this if you don't want the points on the trendline to spawn tooltips
enableInteractivity: false,
// set this to remove the trendline from the legend
visibleInLegend: false
}
}

Related

Qwt Plot - Is it possible to have multiple y-axes with different scales?

I need to have different lines on my plot, with very different values.
One line has values approximately from -4.5 to 4.5, another - from 0 to 10,000.
I need to have them both on one plot, one connected to the left y-axis, another to the right.
And I want to still have a zooming option, so the axes should be both autoscaled.
I tried setting two different axes to different plots with setAxes(), but they are still connected to the left y-axis.
All the forums I read on this question are unclear whether it is possible.
First on your QwtPlot :
setAxisScale( yLeft, 0, 1.8,0.5 );
setAxisScale( yRight, 0, 1000, 0.5 );
Then use on your graph:
curve->setYAxis(yRight);
curve2->setYAxis(yLeft)

Not able to get actual values in decimal places in x axis of matplotlib plot in python [duplicate]

Could someone please guide me on how should I make sure that all ticks (or maybe a better way to specify will be to say all elements in the list passed to plot function) are displayed on the x axis when using matplotlib to plot graphs?
plt.plot(xValues, meanWeekdayArrivalCounts, 'k-')
I want all the values in the list xValues to show up on the graph. By default, only, 0, 10, 20, 30, 40, 50 show up.
Simply add plt.xticks(xValues) to your code. Given the number of points in your graph, the labels might clutter.
You could display them as minor ticks if you set them on the axes object with ax.set_xticks(xValues, minor=True).
use this.
fig = plt.figure(figsize=(10,8))
plt.xticks(np.arange(min(x), max(x)+1, 1.0))
I wanted to show all the years in my graph so I did
plt.xticks(list(table_05.anio.unique()))

Not able to change the axes position qtxlsx

I have generated an Excel chart using Qtxlsx ,and i want to invert the axes from (Left/buttom) to (right/top) but i can't find the functions to change there positions.
Here is the code
Chart *lineChart = xlsx.insertChart(23,3, QSize(600, 400));
lineChart->setChartType(Chart::CT_Line);
lineChart->addSeries(CellRange("A4:A9"));

Pyplot rotated labels offset by one

Just getting into matplot lib and running into odd problem - I'm trying to plot 10 items, and use their names on the x-axis. I followed this suggestion and it worked great, except that my label names are long and they were all scrunched up. So I found that you can rotate labels, and got the following:
plt.plot([x for x in range(len(df.columns))], df[df.columns[0]], 'ro',)
plt.xticks(range(10), df.columns, rotation=45)
The labels all seem to be off by a tick ("Arthrobacter" should be aligned with 0). So I thought my indexing was wrong, and tried a bunch of other crap to fix it, but it turns out it's just odd (at least to me) behavior of the rotation. If I do rotation='vertical', I get what I want:
I see now that the center of the labels are clearly aligned with the ticks, but I expected that they'd terminate on the ticks. Like this (done in photoshop):
Is there a way to get this done automatically?
The labels are not "off", labels are actually placed via their "center". In your second image, the corresponding tick is above the center of the label, not above its endpoint. You can change that by adding ha='right' which modifies the horizontal alignement of the label.
plt.plot([x for x in range(len(df.columns))], df[df.columns[0]], 'ro',)
plt.xticks(range(10), df.columns, rotation=45, ha='right')
See the comparison below :
1)
plt.plot(np.arange(4), np.arange(4))
plt.xticks(np.arange(4), ['veryverylongname']*4, rotation=45)
plt.tight_layout()
2)
plt.plot(np.arange(4), np.arange(4))
plt.xticks(np.arange(4), ['veryverylongname']*4, rotation=45, ha='right')
plt.tight_layout()

How can I correct this behavior on google line chart

I'm trying to plot two series using Google chart, the series does not have the pts
and in the graph i got a discontinuous line for one serie (see the pic below)
Can any one know how to fix this please.
You can change the size of the points by using either the pointSize option or the series.<series index>.pointSize option. Both will take an integer for the point size in pixels. The pointSize option controls the point size for all series (default is 0). The series option overrides the default for specific series.
pointSize: 3
or
series: {
0: {
pointSize: 3 // first series
},
1: {
pointSize: 5 // second series
}
}
To eliminate the gap in the data, you have to set the interpolateNulls option to true:
interpolateNulls: true