MACD plot in python similar to tradingview figure - python

Here is an example of MACD plot using python.
https://code.luasoftware.com/tutorials/algo-trading/python-mplfinance-plot-yfinance-candle-chart-moving-average-macd-and-volume/
I'd like the result (including colors and crossover points, etc.) to be the same as that of tradingview.com
https://www.tradingview.com/script/NDH8bJow-MACD-Colors-Signals/
Could anybody show the python so that it is the same as that of tradingview.com?

Could anybody show the python so that it is the same as that of tradingview.com?
I don't think anyone is going to want to write your code for you.
However what I would recommend is that you work through the mplfinance tutorials on Customizing the Appearance of Your Plots and especially teach yourself about mplfinance styles which shows how to modify the overall color scheme of your plot. See also mplfinance style sheets reference.
For example, to achieve a color scheme similar to trading view you could use the "market colors" from style 'yahoo' and the combine that with mplfinance style 'nightclouds'. Something like this:
mc = mpf.make_marketcolors(base_mpf_style='yahoo')
s = mpf.make_mpf_style(base_mpf_style='nightclouds',marketcolors=mc)
Then when you call mpf.plot() specify kwarg style=s
hth

Related

How can we prevent a funnel chart from bleeding into different levels?

I have a simple dataframe and I'm running this simple code.
from plotly import graph_objects as go
fig = px.funnel(df, x='MeanDispatchedTime', y='Station_Name', color='MED_Type')
fig.show()
Is there some way to get the colors separate and distinct, so the red doesn't bleed into the lower levels? I'm looking at the documentation here.
https://plotly.com/python/funnel-charts/
Or, perhaps, this is completely the wrong chart to be using to tell the story...

Is there a way to draw a radar chart with Altair in python?

I have been using the Altair python API for a Data Visualization project, and everything went smoothly until I wanted to add a radar chart to my app.
I could not find anything on Altair's python API documentation about radar charts, however there seems to be an entry about that in Altair's core documentation but I couldn't access it.
I saw that plotly had that feature but I would really have liked using only one plotting framework...
Is there really no way to make a radar chart with Altair in python ?
This is currently not implemented in VegaLite, you can see the discussion in these two issues and open a new one if you think there is a good case to be made for radar charts:
https://github.com/vega/vega-lite/issues/3805
https://github.com/vega/vega-lite/issues/408
In Altair you might be able to hack something together by layering multiple mark_arc charts with a fillOpacity=0 and a colored stroke (although I don't think this will work since I can't see any way to get right of the lines going towards the middle.

UI Adjustable Matplotlib Color Range

I am using Python's scientific plotting library matplotlib. I am trying to use matplotlib to show an image using imshow. I would like to be able to adjust the color range with in the figure with some type of UI. From what I can tell, there isn't a built-in way to do this in matplotlib, and I have found much on this issue. This is a fairly common use-case and easy to do in MATLAB. How does one do this in matplotlib?
I'm assuming you want to change the cmap attribute. You could use the built-in function input to read some new value from the command line (not really a GUI) or you could use the matplotlib.widgets package which includes e.g. a slider and buttons (see this link for examples).

Safe seaborn theme

I recently discovered seaborn and saw there are many possible combinations of styles. At the moment, I am just using the default Seaborn configuration, to improve on matplotlib style to plot data (basically point series or graphs of functions, not really statistical data).
I discovered Seaborn thanks to prettyplotlib.
Has anyone already thought about a "safe" theme, which renders nicely to plot functions, and aims at rendering nicely for colorblind people or black and white printing?
Thanks
EDIT: I am currently experiencing with "hls" and "Set2" palettes. The later seems to be good for colorblindness, but render very poorly in B&W I think. =(
If you're actually asking about which colormap to use, the authors of matplotlib recently did a very good video about their new default colormap, viridis. viridis is designed to be:
Colorful
Pretty
Sequential
Accurately represent the data ("Perceptually uniform")
...even if printed in black and white
Accessible to colorblind viewers
It looks like this:
I have just came across this blog post about cubehelix which seems to be one of the best option for my use case. This is also available in seaborn: https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.cubehelix_palette.html#seaborn.cubehelix_palette.

Barchart (o plot) 3D in Python

I need to plot some data in various forms. Currently I'm using Matplotlib and I'm fairly happy with the plots I'm able to produce.
This question is on how to plot the last one. The data is similar to the "distance table", like this (just bigger, my table is 128x128 and still have 3 or more number per element).
Now, my data is much better "structured" than a distance table (my data doesn't varies "randomly" like in a alphabetically sorted distance table), thus a 3D barchart, or maybe 3 of them, would be perfect. My understanding is that such a chart is missing in Matplotlib.
I could use a (colored) Countor3d like these or something in 2D like imshow, but it isn't really well representative of what the data is (the data has meaning just in my 128 points, there isn't anything between two points). And the height of bars is more readable than color, IMO.
Thus the questions:
is it possible to create 3D barchart in Matplotlib? It should be clear that I mean with a 2D domain, not just a 2D barchart with a "fake" 3D rendering for aesthetics purposes
if the answer to the previous question is no, then is there some other library able to do that? I strongly prefer something Python-based, but I'm OK with other Linux-friendly possibilities
if the answer to the previous question is no, then do you have any suggestions on how to show that data? E.g. create a table with the values, superimposed to the imshow or other colored way?
For some time now, matplotlib had no 3D support, but it has been added back recently. You will need to use the svn version, since no release has been made since, and the documentation is a little sparse (see examples/mplot3d/demo.py). I don't know if mplot3d supports real 3D bar charts, but one of the demos looks a little like it could be extended to something like that.
Edit: The source code for the demo is in the examples but for some reason the result is not. I mean the test_polys function, and here's how it looks like:
example figure http://www.iki.fi/jks/tmp/poly3d.png
The test_bar2D function would be even better, but it's commented out in the demo as it causes an error with the current svn version. Might be some trivial problem, or something that's harder to fix.
MyavaVi2 can make 3D barcharts (scroll down a bit). Once you have MayaVi/VTK/ETS/etc. installed it all works beautifully, but it can be some work getting it all installed. Ubuntu has all of it packaged, but they're the only Linux distribution I know that does.
One more possibility is Gnuplot, which can draw some kind of pseudo 3D bar charts, and gnuplot.py allows interfacing to Gnuplot from Python. I have not tried it myself, though.
This is my code for a simple Bar-3d using matplotlib.
import mpl_toolkits
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
%matplotlib inline
## The value you want to plot
zval=[0.020752244,0.078514652,0.170302899,0.29543857,0.45358061,0.021255922,0.079022499,\
0.171294169,0.29749654,0.457114286,0.020009631,0.073154019,0.158043498,0.273889264,0.419618287]
fig = plt.figure(figsize=(12,9))
ax = fig.add_subplot(111,projection='3d')
col=["#ccebc5","#b3cde3","#fbb4ae"]*5
xpos=[1,2,3]*5
ypos=range(1,6,1)*5
zpos=[0]*15
dx=[0.4]*15
dy=[0.5]*15
dz=zval
for i in range(0,15,1):
ax.bar3d(ypos[i], xpos[i], zpos[i], dx[i], dy[i], dz[i],
color=col[i],alpha=0.75)
ax.view_init(azim=120)
plt.show()
http://i8.tietuku.com/ea79b55837914ab2.png
You might check out Chart Director:
http://www.advsofteng.com
It has a pretty wide variety of charts and graphs and has a nice Python (and several other languages) API.
There are two editions: The free version puts a blurb on the generated image, and the
pay version is pretty reasonably priced.
Here's one of the more interesting looking 3d stacked bar charts:
(source: advsofteng.com)

Categories

Resources