How do I increase the the size of subplots in pair plot? - matplotlib

I've a dataset in which there are 15 different numeric columns and I would like to plot a pair plot using seaboard. However the image size of subplots is too small to make any inference from it.
I've tried using height and aspect with pair plot. However it doesn't seems to be working for me. The plot size keeps on reducing. The same goes for fig size.
plt.figure(figsize=(40,40))
sns.pairplot(df)
plt.show()
I'm expecting a a good enough size of all the pairs so that some inference can be made on the same. However I'm getting plots too small in size to even recognise the column name.

The command works for me.
I was not aware that in Jupyter notebook we can maximise the output to its actual size.
So essentially, below works just fine.
plt.figure(figsize=(100,100))
sns.pairplot(df)
plt.show()

Related

Matplotlib: Add contour plot to base of surface plot python

So I've produced a 3-d graph on python using trisruf:
ax.plot_trisurf(x,y,z)
and I end up with the following:
3d plot
So now I want to plot contours on the base of this same plot, When I tried using ax.contour(x,y,z) I get an error saying my z should be in 2-dimensions, however my data comes from three 1-d arrays.
How can I go about plotting contours on the base of my graph?
Ok so I managed to find the answer after a bit of searching,
ax.tricontourf(angle_x,angle_y,nlist,zdir='-z', offset = -0.859, cmap='coolwarm') worked, its important to make the offset just slightly lower than the lowest z point (or whatever direction you want the projection) so you can actually see the contour plot!
Here's the result:
updated plot with contour

Matplotlib multiple scatter subplots - reduce svg file size

I generated a plot in Matplotlib which consists of 50 subplots. In each of these subplots I have a scatterplot with about 3000 datapoints. I'm doing this, because I just want to have an overview of the different scatter plots in a document I'm working on.
This also works so far and looks nice, but the problem is obviously that the SVG file that I'm getting is really big (about 15 MB). And Word just can't handle such a big SVG file.
So my question: is there a way to optimize this SVG file? A lot of my datapoints in the scatter plots are overlapping each other, so I guess it should be possible remove many "invisible" ones of them without changing the visible output. (so something like this in illustrator seems to be what I want to do: Link) Is it also possible to do something like this in Inkscape? Or even directly in Matplotlib?
I know that I can just produce a PNG file, but I would prefer to have the plot as a vector graphic in my document.
If you want to keep all the data points as vector graphics, its unlikely you'll be able to reduce the file size.
While not ideal, one potential option is to rasterize only the data points created by ax.scatter, and leave the axes, labels, titles, etc. all as vector elements on your figure. This can dramatically reduce the file size, and if you set the dpi high enough, you probably won't lose any useful information from the plot.
You can do this by setting rasterized=True when calling ax.scatter.
You can then control the dpi of the rasterized elements using dpi=300 (or whatever dpi you want) when you fig.savefig.
Consider the following:
import matplotlib.pyplot as plt
figV, axesV = plt.subplots(nrows=10, ncols=5)
figR, axesR = plt.subplots(nrows=10, ncols=5)
for ax in figV.axes:
ax.scatter(range(3000), range(3000))
for ax in figR.axes:
ax.scatter(range(3000), range(3000), rasterized=True)
figV.savefig('bigscatterV.svg')
figR.savefig('bigscatterR.svg', dpi=300)
bigscatterV.svg has a file size of 16MB, while bigscatterR.svg has a file size of only 250KB.

How do I save color mapped array of same dimensions of the original array?

I have data that I would like to save as png's. I need to keep the exact pixel dimensions - I don't want any inter-pixel interpolation, smoothing, or up/down sizing, etc. I do want to use a colormap, though (and mayber some other features of matplotlib's imshow). As I see it there are a couple ways I could do this:
1) Manually roll my own colormapping. (I'd rather not do this)
2) Figure out how to make sure the pixel dimenensions of the image in the figure produced by imshow are exactly correct, and then extract just the image portion of the figure for saving.
3) Use some other method which will directly give me a color mapped array (i.e. my NxN grayscale array -> NxNx3 array, using one of matplotlibs colormaps). Then save it using another png save method such as scipy.misc.imsave.
How can I do one of the above? (Or another alternate)
My problem arose when I was just saving the figure directly using savefig, and realized that I couldn't zoom into details. Upscaling wouldn't solve the problem, since the blurring between pixels is exactly one of the things I'm looking for - and the pixel size has a physical meaning.
EDIT:
Example:
import numpy as np
import matplotlib.pyplot as plt
X,Y = np.meshgrid(np.arange(-50.0,50,.1), np.arange(-50.0,50,.1))
Z = np.abs(np.sin(2*np.pi*(X**2+Y**2)**.5))/(1+(X/20)**2+(Y/20)**2)
plt.imshow(Z,cmap='inferno', interpolation='nearest')
plt.savefig('colormapeg.png')
plt.show()
Note zooming in on the interactive figure gives you a very different view then trying to zoom in on the saved figure. I could up the resolution of the saved figure - but that has it's own problems. I really just need the resolution fixed.
It seems you are looking for plt.imsave().
In this case,
plt.imsave("filename.png", Z, cmap='inferno')

How to control the specific size of plot in matplotlib?

Let us suppose that I am plotting a few plots with pyplot/matplotlib. Now, the first has to have tick marks and tick labels, and only the first. The last has to have a colorbar and some marks for scale. If I do a script specifying the figure size, the plot proper in the last and first plots is drawn with smaller sizes, as the figure has to make room for the extra markings. And I seem to be not able to control that, in an automatic way, like making the other plots at the same scale inside a larger figure or something like that.
Example code (it looks a little non-pythonic because I am using PyPlot inside Julia):
using PyPlot
SomeData=randn(64,64,3)
for t=1:3
figure(figsize=(3.0,3.0))
imagen=imshow(SomeData[:,:,t], origin="lower")
if t!=3
xticks([])
yticks([])
else
tick_params(labelsize=8, direction="out")
end
if t==1
cbx=colorbar(imagen, fraction=0.045, ticks=[])
cbx[:set_label]("Some proper English Label", fontsize=8)
end
savefig("CSD-$t.svg",dpi=92)
end
Thanks in advance-

converting diurnal scatter plot into heatmap plot

I have created a diurnal plot of date vs. time but it is rather messy and I'd prefer to create a heatmap. Something similar has been done here, but it doesn't work as I can't parse the time in as well. I tried this which works for the x-axis but I can't do the y.
Ideally, it would have a legend on the size showing how much data is in each 2D bin. How do I parse the x and y axis in such that numpy.histogram2D/imshow can read it or meshgrid/pcolormesh can be used?