I have a text file that is constantly updating a single value. I'm trying to display this value using matplotlib's animation but I'm having lots of issues.
For example I want to show a value that's changing every second on the text file (value ranges from 0 to 150) and I want the height of bar graph to increase and decrease with this value.
I want to do the same with horizontal graph. I also want to show a dot moving around the circle for different values (between 0 and 360).
I've tried to many things but it constantly broke the code or matplotlib froze. I've been trying to use matplotlib's animation.
Any help would be appreciated.
Related
I am working on a multi-line animated chart based on [Edit: not Bostock's] example:
http://bl.ocks.org/atmccann/8966400
I want the lines to appear synchronized by the date value on the x axis. If I slow down the graph (say to duration=15000) I can clearly see that in the very early part of the graph the green line is ahead of the black line. Then the black line moves ahead of the green line. Both start and end together.
The issue is accentuated in my chart where I am plotting 20 lines. Some are clearly ahead of the others when plotting. Lines with initial y values of zero shoot way ahead of those that climb to higher y values at the start.
How can I adjust the display so both lines paint for the same date at the same time?
The technique in the bl.ocks.org example (which, btw, is not Bostock's) is animating based on the length of the line, not it's position on the y-axis. If you want to animate based on the y-axis position, you'll have to use a different technique. Especially with 20 lines, I wouldn't recommend trying to dynamically update each line if they have a lot of points. You could do that if there aren't many points, though.
A simple approach would be to add a solid (white) rectangle to the chart that covers all the graph lines. Then animate the left position and width of that rectangle to reveal the lines over time.
I would like to have a graph in amCharts where the x-axis is the time and bars represent in different colors and heights representing events in time. Now I would like to have that zoom-able so that captions in the bars only appear if there is enough space to display them.
In my example picture the caption is not displayed on the magenta bars:
:
I would try to do this with a date-based serial chart. You could try using a separate step line for each column with fillAlpha set to 1 or one step graph and use fillColorsField and set color in your data at a position where color should be changed. As for labels, it's more complicated - graph has hideLabelsCount property, but it will show/hide all labels once certain zoom level is reached. You could try employ labelFunction of a graph and usesome function which would set label to empty string, depending on zoom level.
I have a large dataset in an array which translates into about a million 6-pixel wide bars,
Given that about 130 bars fit into 800 pixels of screen, I need to only display a portion of the data at a time. Then, when the user pans the chart, new data will be added and non-visible data will be removed. The user could pan right or left so data need to be able to enter and exit from both sides of the chart.
I feel like the solution involves D3's enter and exit, but I'm unsure how to implement it.
One idea I've had is to use Array.prototype.concat and redraw on pan. Another idea would be to use Array.prototype.slice. I hope those are fast enough.
Any examples?
There are no examples that I'm aware of. Roughly, you would need to do the following.
Draw the initial bar chart. Pass in only the data you'll display (i.e. the first 130 data points if your screen is 800px wide).
On pan, get the translation for the pan. The x translation corresponds to a certain number of bars. Take off this many data points from the beginning of your data array and add that many to the end.
Pass that new data array to D3 and redraw. This tutorial should give you some pointers. Remember to pass a key function to .data() so it knows how to match data to DOM elements.
Similar thing on subsequent pans. Figure out how many bars have been panned and modify the data array accordingly (e.g. using slice and concat -- doesn't matter that much). Redraw the bars.
The concept is very similar to what's done in the tutorial I've linked to, except that the redraw isn't triggered by a timer, but by the pan event.
There are fundamentally two ways to do this. One is that you draw all 1M bars using svg and rely on svg's built in panning. The other is that you draw 130 bars and redraw each time the user pans. enter() and exit() are useful for doing things to data elements in your set that are entering or exiting the scene since the last time it rendered. (d3 determines which elements are
"new" by calling a predicate function on each element. The function has a default but can be user supplied.) You don't actually have to use them here unless you want to be fancy. You can just selectAll the rects from last draw, and .data() them with your new data, and supply the usual calls for drawing rects.
I'm looking to chart some time-based data over the course of multiple days (using a simple line chart). I'd like to present the time of day as a gradient of color in the background of the line graph. Noon of each day would be white, midnight is nearly black, and all other hours in between are a smooth greyscale in between.
I can do this very, very clunkily by drawing rectangles before my lines, but it has the following problems:
1. hours without a data point don't get a rectange, leaving a gap in my background
2. the transition is not smooth, but stepped
It seems that the best way to fill in the gaps would be to latch onto the ticks along the x-axis, as those are regularly spaced regardless of the data points. Is there a way for me to apply a gradient, either CSS or SVG, along with the tick marks, that will smoothly flow from one to the other (that is, no gaps between where one gradient ends and the other begins, nor any overlap)? If I add or remove data, the gradient should change accordingly.
Any and all assistance greatly appreciated.
just define the gradient in a <def> section, and place rectangles aligned with the days you are charting. set the fill attribute to url("#the_gradient").
have a look here http://www.w3.org/TR/SVG/pservers.html
So I am using jqPlot to display distance (y-axis) over time (x-axis) in a simple line graph.
However, while I have actual distances as the underlying data used to position the points, I'm not interested in displaying those distances on the y-axis.
Instead, there are a series of landmarks at given distances, that I want to appear on the y-axis as a 'tick' next to the appropriate point for the distance to that landmark. That way the line appears to "pass" each landmark as it travels upward.
Currently I'm "faking" this by hiding the ticks and putting a manually-created series of labels next to the graph. This works well enough, but I had to disable vertical zooming because if the user chose to zoom in, the labels would not match up with the actual distances. My users would really like to zoom in vertically, however, and I want to allow them to.
Therefore, does anyone know of a way (a plugin or similar) that would allow me to associate custom labels with given tick marks in jqPlot, that will match up nicely and respond to zooming? It would be necessary to hide some of the landmarks if the graph is zoomed out too much, so that would have to be a feature.
Alternatively, if someone knows of a "zoom event" that passes in the min and max y values, I could probably recreate my manual labels with that data, so let me know if you know of a way to get that information. I haven't been able to find one.
I would need to see a bit of your code to customize it to the distance but to start with you could label the ticks and it will display over the size of the chart.
axes:{yaxis:{ticks:['DiscanceA','DiscanceB', 'DiscanceC', 'DiscanceD', 'DiscanceE'],
renderer: $.jqplot.CategoryAxisRenderer,},
Let me know how it goes and if you have any code lets see it!