Is it possible to add an arrow to a figure in matplotlib, rather than an axis please?
I have a multi-component figure containing numerous axes, and want to be able to draw arrows between them. However, if I do this manually by setting the ax.arrow() to extend out of the axis, then it is cropped and doesn't show.
Thanks
if you set clip_on = False for your ax.arrow, it should extend outside the axis
Heres a minimal example:
import matplotlib.pyplot as plt
fig,ax=plt.subplots(1)
ax.arrow(0.5,0.6,0.55,0.,fc='r',ec='r',clip_on=True)
ax.arrow(0.5,0.4,0.55,0.,fc='b',ec='b',clip_on=False)
plt.show()
Related
I've set my plot to transparent so when i access it after plotting,axis and labels looks dark
How can i set the label's and axis to "white" .??
I've tried this
import seaborn as sns
DATA=sns.load_dataset("tips")
import matplotlib.pyplot as plt
plt.figure()
sns.set_style(style="white")
ax=sns.clustermap(DATA.corr(),
cmap="viridis")
#ax.xaxis.label.set_color('white')
#ax.yaxis.label.set_color('white')
plt.savefig("clustermap",transparent=True)
Note that i don't want to change the ' background ' color, just the label and axis color
You can probably use the seaborn.set() function. Here you have a previous answer:
Setting plot background colour in Seaborn
Here you have an example it seems to work in your case (at least in my environment ;-) ):
sns.set(rc={'axes.facecolor':'white', 'figure.facecolor':'white'})
to change just the axis's labels you can use this:
sns.set(rc{'ytick.labelcolor':'white','xtick.labelcolor':'white'})
There are a lot of very fine parameters to set your plot. You can review the full list of parameters just with the command:
plt.rcParams
You can get many details on such command in the link I gave before, going to the Joelostblom answer
I need some help to make my cph plot bigger, but unfortunately, it seems like figsize can't be applied on this plot! Can somebody help me please?
I'm using Jupyter Notebook on pandas!
cph.plot()
Here the problem is that the plot function actually plots my features, but they are too much so their names overlap and I can see nothing! I need the plot to be bigger!
Seems like cph.plot() calls matplotlib.pyplot.plot in the back-end. By default, Matplotlib uses the last created figure, so creating a figure with your specified width and height should do the trick:
import matplotlib.pyplot as plt
# 8, 12 => width and height in inches
plt.figure(figsize=(8, 12))
cph.plot(/*your params here*/)
See if this works.
you can try the following command:
import seaborn as sns
sns.set(rc={'figure.figsize':(18,10)})
cph.plot()
I am using Seaborn to plot some data in Pandas.
I am making some very large plots (factorplots).
To see them, I am using some visualisation facilities at my university.
I am using a Compound screen made up of 4 by 4 monitors with small (but nonzero) bevel -- the gap between the screens.
This gap is black.
To minimise the disconnect between the screen i want the graph backgound to be black.
I have been digging around the documentation and playing around and I can't work it out..
Surely this is simple.
I can get grey background using set_style('darkgrid')
do i need to access the plot in matplotlib directly?
seaborn.set takes an rc argument that accepts a dictionary of valid matplotlib rcparams. So we need to set two things: the axes.facecolor, which is the color of the area where the data are drawn, and the figure.facecolor, which is the everything a part of the figure outside of the axes object.
(edited with advice from #mwaskom)
So if you do:
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn
seaborn.set(rc={'axes.facecolor':'cornflowerblue', 'figure.facecolor':'cornflowerblue'})
fig, ax = plt.subplots()
You get:
And that'll work with your FacetGrid as well.
I am not familiar with seaborn but the following appears to let you change
the background by setting the axes background. It can set any of the ax.set_*
elements.
import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
m=pd.DataFrame({'x':['1','1','2','2','13','13'],
'y':np.random.randn(6)})
facet = sns.factorplot('x','y',data=m)
facet.set(axis_bgcolor='k')
plt.show()
Another way is to set the theme:
seaborn.set_theme(style='white')
In new versions of seaborn you can also use
axes_style() and set_style() to quickly set the plot style to one of the predefined styles: darkgrid, whitegrid, dark, white, ticks
st = axes_style("whitegrid")
set_style("ticks", {"xtick.major.size": 8, "ytick.major.size": 8})
More info in seaborn docs
I have a polar axes in matplotlib that has text which extends outside of the range of the axes. I would like to remove the border for the axis -- or set it to the color of the background so that the text is more legible. How can I do this?
Simply increasing the size of the axes is not an acceptable solution (because the figure is embeddable in a GUI and it becomes too small if this is done). Changing the color of the background to be black so that the border is not visible is also not an acceptable solution.
A considerable amount of code that does various parts of plotting things is omitted, but here is the generation of the figure and axes itself:
import pylab as pl
fig = pl.figure(figsize=(5,5), facecolor='white')
axes = pl.subplot(111, polar=True, axisbg='white')
pl.xticks([])
pl.yticks([])
pl.ylim(0,10)
# ... draw lots of things
Just add this line: axes.spines['polar'].set_visible(False) and it should go away!
eewh, all the anatomy terms.
A more general way (independent of coordinate systems) is:
axes.axis("off")
I'm trying to plot two sets of data in a bar graph with matplotlib, so I'm using two axes with the twinx() method. However, the second y-axis label gets cut off. I've tried a few different methods with no success (tight_layout(), setting the major_pads in rcParams, etc...). I feel like the solution is simple, but I haven't come across it yet.
Here's a MWE:
#!/usr/bin/env python
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
matplotlib.rcParams.update({'font.size': 21})
ax = plt.gca()
plt.ylabel('Data1') #Left side
ax2 = ax.twinx()
for i in range(10):
if(i%2==0):
ax.bar(i,np.random.randint(10))
else:
ax2.bar(i,np.random.randint(1000),color='k')
plt.ylabel('Data2') #Right
side
plt.savefig("test.png")
I just figured it out: the trick is to use bbox_inches='tight' in savefig.
E.G. plt.savefig("test.png",bbox_inches='tight')
I encountered the same issue which plt.tight_layout() did not automatically solve.
Instead, I used the labelpad argument in ylabel/set_ylabel as such:
ax.set_ylabel('label here', rotation=270, color='k', labelpad=15)
I guess this was not implemented when you asked this question, but as it's the top result on google, hopefully it can help users of the current matplotlib version.