matplotlib interactive plot with slices of image [closed] - python

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How would I make an interactive plot like the one displayed here? I'd like to show an image with x and y slices of the image taken at a point that can be adjusted by clicking on the image.
I know this one was made in Chaco, but since Chaco isn't compatible with python3, just matplotlib or bokeh would be preferable.

Using tacaswells suggestion, I found that the cross_section_2d in bubblegum was just what I was looking for.
First I installed bubblegum from github https://github.com/Nikea/bubblegum.git
Then the following sets up a cross_section image
import matplotlib.pyplot as plt
import numpy as np
from bubblegum.backend.mpl.cross_section_2d import CrossSection
fig= plt.figure()
cs= CrossSection(fig)
img= np.random.rand(100,100)
cs.update_image(img)
plt.show()
Thanks!

Related

How to create a graph chart without using Libraries (Matplotlib) in Python? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last year.
Improve this question
I'm new to python. In an interview, the Hr ask me to create the Graph chart without using the Library like matplotlib. I tried a few ways but it does not work for me I've not cleared the interview as well. And people if you know how to make the graph like mentioned below without using a lib. Please share with me. any kind of suggestion is appreciatable.
HHhhmmm. Sounds like somebody is trying to check your ability to think outside the box and/or your knowledge of print formatting since it is never a good idea to reinvent the wheel on not use a better solution that already exists. I generated some random numbers and 'plotted' a * using print statements.
I included a Matplotlib plot just to check how close it was. You could add some code to calculate the derivative and change the symbol based on that.
import math
import random
import matplotlib.pyplot as plt
x=range(50)
y= [random.randrange(0,5) for i in range(50)]
for yindex in range(5,-1,-1):
for xindex in range(0,50,1):
if y[xindex] == yindex:
print("*", end='')
else:
print(" ", end='')
print()
fig, ax = plt.subplots()
ax.plot(x,y)
plt.show()
plot

Cluster label plotting [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I have cluster labels in one columns and one more column to make comparison or analyze the clusters.
import pandas as pd
parties_and_cluesters = pd.DataFrame({'Parties':['A','B','C','C','A','No Party','B','A'],
'Clusters':['Cluster 2','Cluster 1','Cluster 4','Cluster 4','Cluster 3','Cluster 0','Cluster 3','Cluster 2',]
})
What is the best way to see the outcome? I thought plotting bar-plot but didn't sound good to me. I want to see if clusters reasonable.
Question not clear. If wanted to visualize and feel nice try seaborn count plot
import seaborn as sns
ax = sns.countplot(x="Clusters", data=parties_and_cluesters)
Following your comments
parties_and_cluesters.groupby('Clusters')['Parties'].value_counts().unstack().plot.bar()
In addition to above answer, you may want to display it as stacked. And as I saw from the chat, you can use legend as a seperate part of your plot.
plt.figure(figsize=(20,10))
parties_and_cluesters.groupby('Clusters')["Parties"].value_counts().unstack().plot.bar(stacked=True)
plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left')
plt.gcf().set_size_inches(10, 5)

i want to get some approaches to update the content of ax windows automatically in python [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
just mean update the content automatically from my plot command
I am searching for a long time on net. But no use. Please help or try to give some ideas how to achieve this.
This will update a plot
import matplotlib.pyplot as plt
import numpy as np
data = np.random.random(20) # inital data set
f,ax = plt.subplots() # create the figure and plot
ax.plot(data) # plot initial data
for _ in range(10):
data = np.random.random(20) # create new data
ax.cla() # clear subplot's current data
ax.plot(data) # plot new data
plt.pause(0.01) # wait a few secs to allow plot to update
f.canvas.draw() # draw the plot again (in the same window)
The important bit here is to clear the current content and then draw again. For some reason to do with the way matplotlib handles plotting there needs to be a pause between the plot command and the draw command (or you have to flush the changes).

Is displaying an image using matplotlib.pyplot a graph? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Input:
import scipy.misc
import matplotlib.pyplot
matplotlib.pyplot.imshow(scipy.misc.lena())
The following code displays an image of a woman on a 500 x 500 grid. My questions are as follows:
1.Is this technically considered a graph? (From my knowledge a graph is the relationship between an x coordinate to a y coordinate, this seems to not be the case, but the numbers on the sides makes it confusing)
2.What do the numbers on the x and y axis represent? Is that only the sizing?

plot Planetary Boundary layer height [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I would like to know if someone has an easy program to plot Planetary Boundary Layer height on a map (2D in lat/lon) in fortran 90 or python (or NCL).
I am using a program in F.90 but it is not working so I would like to compare with a second program.
Thank you
Here's a Python example with matplotlib and netCDF4 modules:
import matplotlib.pyplot as plt
from netCDF4 import Dataset
nc = Dataset('mydatafile.nc','r')
lon = nc.variables['lon'][:]
lat = nc.variables['lat'][:]
pblh = nc.variables['pblh'][:]
nc.close()
plt.contourf(lon,lat,pblh)
plt.colorbar()
plt.savefig('pblh.png')
ptl.clf()
You may need to edit this example to match your data, e.g. filename, variable names etc.

Categories