Safe seaborn theme - python

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.

Related

MACD plot in python similar to tradingview figure

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

What functions in python matplotlib or seaborn to customize each box in the heatmap?

This figure seems to be generated using python seaborn. But how exactly is each box customized with different shape (star or dot) and background color (size)?
Thanks!
I believe the graph in question was created in the R language 'ggplot2'.
stackoverflow,Correlation Heatmaps in R
The Python seaborn provides the following customization examples.Better Heatmaps and Correlation Matrix Plots in Python
The process I found this answer is to search for the posted image in Google (by right-clicking on it) I'm checking out each of these sites, and I encourage you to take a look at them as well. If you've already searched and posted on our site, you're good to go.

certain seaborn plot colors not displaying on projector

I often have to present my data analyses in meetings where we either use a projector or a large TV monitor, an example plot might look like this (generated with seaborn):
I've noticed that often times, certain colors will not show very well (if at all) on these displays, whereas it shows just find on my computer monitor. For example, in this example, the gray background will not show at all.
Is there another set of colors I can use that are "safe" to use with projectors and TV monitors?
I guess the problem is caused by bad contrasts or dynamic ranges of cheap projectors. By default, seaborn uses somewhat muted low-contrast color schemes because these are nicer to the eye.
You can use the function seaborn.set_palette to change the colors used.
The seaborn documentation has a nice page about color palettes that explains how to create different color schemes.
For example, seaborn.set_palette(seaborn.hls_palette(8, l=.3, s=.8)) gives 8 rather dark colors (lightness 0.3) that I believe will work well with projectors:
P.S. There is also a dark variant of the default six-color palette in seaborn. I have not tried, but I think it can be set by seaborn.set_palette('dark')
P.P.S. These color palettes have no effect on the background, though. This answer may help out there.

Plot functions in Python

I am required to use Python for engineering project. Need to create many graphs, including surface plots. In the past I used Matlab for plotting and really liked it. I was wandering if there is a module/package/extension which bring similar capability into Python.
To be more specific, I need piloting for 2 different reasons.
To understand how functions behave. Something quick and dirty would do it.
Publication/presentation. Ability to add labels, legend, grid, customise colour, axis properties etc.
Try matplotlib, it's pretty extensive and has a shell similar to MATLAB / Mathematica.
I suspect matplotlib.pyplot would be right up your alley.

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