This question already has answers here:
How to add hovering annotations to a plot
(12 answers)
Closed 3 years ago.
How can I plot a figure in Python like MATLAB with the following features?:
1) I can zoom in and zoom out.
2) I can modify the range for x and y on the figure
3) I can click on the figure to see actual numbers related to each data point
Another question, how can we specify with wath resolution the matplotlib saves the figure?
To the best of my knowledge, MATPLOTLIB does not have that. Anything else?
I would recommend looking at plotly.
Plotly allows you to make graphs that can be
1) zoomed in on
2) change the x and y-axis numbers by dragging on the axes (but cant switch from say, log scale to linear scale as easily -- something like this would require an interaction feature)
3) Plotly allows you to display info on cursor-hover
For an example of a plotly plot in use, see this washington post page.
Related
This question already has answers here:
Matplotlib: How to plot images instead of points?
(2 answers)
How to insert a UTF-8 character onto an image
(1 answer)
Placing Custom Images in a Plot Window--as custom data markers or to annotate those markers
(5 answers)
How to make a tkinter canvas background transparent?
(2 answers)
Closed last month.
I wanted to make a chess game in python, but then I saw that you can do a lot of amazing things in matplotlib in terms of designing. I know that this is probably not the best way of doing this but I want to try this. Here is my main question.
How to scale and position images in matplotlib and tell me a bit more about it if possible?
This is what I have at this point:
import matplotlib.pyplot as plt
im = plt.imread('C:\\...\\bb.png')
imgplot = plt.imshow(im)
plt.show()
This just displays the image, I cant realy scale it nor position it.
I also found something like this, it displays the image in the right corner but I can't change anything or it just disappears or nothing happens... In short only misery.
newax = fig.add_axes([0.6,0.8,0.2,0.2], anchor='NE', zorder=1,)
newax.imshow(im)
newax.axis('off') #If I remove this there is a frame
Please help me out.
This question already has answers here:
How to adjust padding with cutoff or overlapping labels
(8 answers)
Closed 4 years ago.
So I'm using yellowbrick in Python, which is basically matplotlib and scikit-learn combined, to visualize some data.
My chart looks like this:
The labels get cut off. What I want to do is to adjust the figure so the labels on the right don't get cut off. I tried
plt.rcParams['figure.figsize'] = (10, 5)
plt.rcParams['font.size'] = 12
but when I rendered the figure, it's still cut off. Even when I save it as a png file it's still cut off. What am I missing here?
tight_layout method should solve your problem.
Generally you can use it with:
fig.tight_layout() # if fig is your figure handle
or
plt.tight_layout() # if stated within the context of your figure
This line of code should be added after the last plotting statement just before rendering the figure.
If this does not work, please post a fully working minimal code example, as described in mcve. Afterwards I'll be able to post a fully working solution for most, if not all, cases.
This question already has answers here:
How to remove gaps between subplots in matplotlib
(6 answers)
Closed 5 years ago.
I am attempting to plot a graph similar to the one attached below. The y-axis should be aligned and the x-axis scale and name should be same. Also, I want the dotted line as shown in the figure.
I tried combining two different graphs but that is certainly not a good way to solve this.
Sorry for the poor quality picture but the important points are mentioned.
Look into the matplotlib docs. I think you might be looking to use plt.subplots with the sharex argument.
This question already has answers here:
How to create 3D joint density plot MATLAB?
(3 answers)
Closed 5 years ago.
I have a 3D dataset which I visualize with a scatter plot. This is how it looks like:
I would now like to color the different dots depending on the density of the data. Is there any way I can do this in Python or MATLAB? Another option could be to bin the data and color the bins depending on how many data points lie within them. I binned the data by using Python's histogramdd function.
H,edges = np.histogramdd(al,bins=(16,16,16))
The idea is to have it look kind of like this:
using the code provided in this thread: 3D discrete heatmap in matplotlib
If you have any ideas on how I could do this, I would be really happy to hear them!
Thank you all for your ideas. Using the hist3 fundtion does unfortunately not work since I have 3 dimensions and hist3 takes only two variables and calculates the histogram values as the third. My solution for now is to calculate for each data point the number of points which are in a certain radius. Then I use these values to color my plot with scatter3(x,y,z,2,c)
c=zeros(size(x));
for i=1:length(x)
j=1:length(x);
j(i)=[];
s = sort((x(j)-x(i)).^2+(y(j)-y(i)).^2+(d(j)-d(i)).^2);
c(i)=sum(s<2);
end
scatter3(d,x,y,2,c)
This question already has answers here:
Matplotlib: -- how to show all digits on ticks? [duplicate]
(2 answers)
Closed 6 years ago.
On the x-axis, my units are in ns as this is what the physics dictates. However, I don't want the exponential text highlighted to be seen.
Is there anyway this can be removed while keeping the x-axis units the same?
One further question is with regards to sharing the x-axis between the two plots. I want the residual plot on the bottom to be connected to the top while resizing the y-axis.
Previously I set the hspace of the subplots to be 0 but this makes the y-axis values overlap. Are there any solutions to this?
I'd like to point out also that I'm using QuTiP if anyone has expertise in this then that'd be greatly appreciated. I'm sure it should be easy enough to convert the code into a QuTiP style either way.
Any help is appreciated!
Multiply your x data by 1e9, so that you actually plot nanoseconds.