I'm trying to create a heatmap for stock returns like the one used in https://finviz.com/map.ashx, which looks like:
Does anyone know how to create something like this in python? The closest I've found is "Heatmap with Unequal Block Sizes" for plotly, https://plotly.com/python/heatmaps/. I could probably make that work by subdividing everything into dozens of smaller heatmaps and then gluing them together in Dash, but is there a better way? Does anyone know of a tool that makes this type of graph, or would I have to make it from scratch?
Related
I am implementing the Fastdtw algorithm to find the optimal path to align two time-series data. I hope to output a plot like this:
However, I've never tried such kind of plot before. I guess maybe I need to use the imshow() function in matplotlib, but I don't know how to draw the extra trajectory in the plot.
I wish somebody coould give a similar example about drawing like such style. I will modify the parameters by myself.
I've been trying to create a sunburst plot using the plotly.express library in Python. I came up with two different methods (first method: the dataframe contains the ID and parent (fig. 1), second method: the dataframe contains the ID and complete path (fig. 2)).
Fig. 1 Fig. 2
I have decided to keep the second method – I added some features in the second one, hence the differences in the plots – but I would like the text inside the sectors to look like they looked with the first method (i.e. orientation either horizontal or radial (not tangential) + smaller text).
I know how to force the text to be only horizontal or only radial, using
fig.update_traces(insidetextorientation = 'radial') # or 'horizontal'. But I want Plotly to be able to choose between the two, like it would do if I selected 'auto'. In fact, I just don't want it to be tangential. Is there a way to do that?
Also, if anyone knows why by default the ID/parent way looked like that when the ID/path way looked messier, I'd love to know. I have found a way to force the text to be smaller (fig.update_layout(font_size = 8)) but I feel like it still doesn't look as good.
Thank you for your help!
So looking around i've seen a few posts about combining graphs online,but none seem to apply to the graphs im using. while i'm happy to use matplotlib I can't seem to get my code to work in that while it does work in panda.
df = pd.read_excel (r'FILE-Location', index_col='PT: TD: BP')
df.iloc[1:2].T.plot()
df.iloc[2:3].T.plot()
These are the two seperate plots I wish to plot onto the same graph. I know it's a weird request and I could very easily combine them by making it [1:3] however I wish to keep them seperate as I plan to have them as options on tkinter, in which you can check a box of which lines you would like displayed, in order to do this I have to keep them seperate.
Thanks for any help solving this.
Edit: thanks for linking a similiar post, I tested the methods given there and they all seemed to simply plot into four seperate graphs within the same figure, while im looking for all four overlayed onto the same graph.
I am trying to make a swam plot that contains more information than a single categorical level and two variables. I am looking to create something like this
So ideally, something like this would work (but it does not):
ax = sns.swarmplot(x="round_id", y="independent_error_abs", hue="difficulty", hue_order=['easy','medium','hard'], size="followers", markershape="rank",data=df)
where "difficulty", "followers", and "rank" determine the color of the point, the size of the point, and the shape of the point, respectively.
No, this is not possible with swarmplot. Personally I find this kind of plot very difficult to interpret: a good statistical plot should make the patterns in the data immediately apparent, whereas plots with multiple categorical variables that manipulate the size or shape of the points quickly become more like puzzles. My recommendation in these cases (following Andrew Gelman) is to make more than one plot, each with relatively simple semantics.
You don't have to agree, of course, but you will have to make it yourself using matplotlib.
I am facing the same issue, and actually the solution seems to be pretty simple at least for the marker type!
Just divide your dataframe in subdataframes, each for a different marker type. The you make a swarmplot on top of each other, and that's it.
If the size of the dot, is also a categorical variable, you just need to do the same as above where each subdtaframe will represent a marker and a different size.
If size is continuous, then it seems you would need to plot each dot independently in a for loop, but for that I would use matplotlib.pyplot.
I have a large data set of tuples containing (time of event, latitude, longitude) that I need to visualize. I was hoping to generate a 'movie'-like xy-plot, but was wondering if anyone has a better idea or if there is an easy way to do this in Python?
Thanks in advance for the help,
--Leo
get matplotlib
The easiest option is matplotlib. Two particular solutions that might work for you are:
1) You can generate a series of plots, each a snapshot at a given time. These can either be displayed as a dynamic plot in matplotlib, where the axes stay the same and the data moves around; or you can save the series of plots to separate files and later combine them to make a movie (using a separate application). There a number of examples in the official examples for doing these things.
2) A simple scatter plot, where the colors of the circles changes with time might work well for your data. This is super easy. See this, for example, which produces this figure
alt text http://matplotlib.sourceforge.net/plot_directive/mpl_examples/pylab_examples/ellipse_collection.hires.png
I'd try rpy. All the power of R, from within python.
http://rpy.sourceforge.net/
rpy is awesome.
Check out the CRAN library for animations,
http://cran.r-project.org/web/packages/animation/index.html
Of course, you have to learn a bit about R to do this, but if you're planning to do this kind of thing routinely in future it will be well worth your while to learn.
If you are interested in scientific plotting using Python then have a look at Mlab: http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html
It allows you to plot 2d / 3d and animate your data and the quality of the charts is really high.
Enthought's Chaco is designed for interactive/updating plots. the api and such takes a little while to get use to, but once you're there it's a fantastic framework to work with.
I have had reasonable success with Python applications generating SVG with animation features embedded, but this was with a smaller set of elements than what you probably have. For example, if your data is about a seismic event, show a circle that shows up when the event happened and grows in size matching the magnitude of the event. A moving indicator over a timeline is really simple to add.
Kaleidoscope (Opera, others maybe, Safari not) shows lots of pieces moving around and I found inspirational. Lots of other good SVG tutorial content on the site too.
You might want to look at PyQwt. It's a plotting library which works with Qt/PyQt.
Several of the PyQwt examples (in the qt4examples directory) show how to create "moving" / dynamically changing plots -- look at CPUplot.py, MapDemo.py, DataDemo.py.