Which command in my code is preventing a custom theme and legend labels from working? - ggplot2

So i am trying to make graph mapping coral cover degradation. From the attached graph you can see i am almost there, i am just trying to add custom labels to my legend and a custom theme to change up the colours.
This code produces a graph but seems to ignore my custom theme and labels.
Thanks for the help!
ggplot(CCR, aes(x=as.factor(Year),y=mean, group=Site,color=Site))+
geom_point(size=3)+
labs(y="Hard Coral Cover %",x="Year")+
geom_line(size=2)+
geom_errorbar(aes(ymin=mean-sd,ymax=mean+sd),width=.1,colour="black")+
scale_y_continuous(limits=c(0,110), expand=c(0,0))+
theme(axis.title.y = element_text(face="bold"),axis.title.x=element_text(face="bold"),legend.title=element_text(face="bold"))+
scale_fill_npg(labels=c("Bouy 3","Sampela 1","Pak Kasims","Kaledupa 1","Kaledupa Double Spur","Ridge 1"),guide=guide_legend(title="Site"))+
theme_base()
Graph produced from above code

Related

How to set Texture.F_srgb for actor model

In the official panda3d guide for blender model conversion, under the "Why do my colors look different in Panda3D?" header they say you need to set SRGB mode for colors to look like they do in blender
Set your textures to use the Texture.F_srgb or Texture.F_srgb_alpha texture format, which automatically linearizes the colors before they are used in the rendering process.
How exaclty do I do that? I load my model as Actor, I tried getting to the textures with findTexture() but had little to no success.
self.actor = Actor(model_path, animation_dict)
# how to set Texture.F_srgb?

How to resize a nifti (nii.gz medical image) file

I have some medical images of nii.gz format which are of different shapes. I want to resize all to the same shape inorder to feed to a deep learnig model, I tried using resample_img() of nibabel, but it destroys my images. I want to do some other function just to resize it to a particular shape, say (512,512,129).
Someone please help me in this regard. I am stuck in this step for quite a good number of days.
Maybe you can use this:
https://scikit-image.org/docs/dev/api/skimage.transform.html
I saw it in one of the papers. Here is the example in function ScaleToFixed:
https://github.com/sacmehta/3D-ESPNet/blob/master/Transforms.py
Here is how I did it. I have the volume of shape 320x320x130 (black and white so no rgb dimension). I want to make it twice as small. This worked for me:
import skimage.transform as skTrans
im = nib.load(file_path).get_fdata()
result1 = skTrans.resize(im, (160,160,130), order=1, preserve_range=True)
You can use TorchIO:
import torchio as tio
image = tio.ScalarImage('path/to/image.nii.gz')
transform = tio.CropOrPad((512,512,129))
output = transform(image)
If you would like to keep the original field of view, you could use the Resample transform instead.
Disclaimer: I'm the main developer of TorchIO.

PyQt application issue with matplotlib bar graph x ticks

I'm making a application to show graph using python pyqt5 and matplotlib.
here is a issue with graph I don't know why this happen.
You can see the 2 graph image I uploaded.
Second one is what I want to show.
But after show pie graph(There are so many types of graph I used in my application but only after pie graph happen this issue), it work like first image.
So, I wrote code after draw pie graph
self.MplWidget.canvas.axes.clear() like this.
But it doesn't change at all.
If I reboot my application it work well.
How I can show my graph like image2 after show pie graph?
this is my code to show bar graph
self.MplWidget.canvas.axes.bar(ind, graph1, width, label='price1' )
self.MplWidget.canvas.axes.bar(ind, graph2, width, bottom=graph1, yerr=Std, label='price2')
self.MplWidget.canvas.axes.title.set_text('graph1')
self.MplWidget.canvas.axes.set_xticks(ind)
self.MplWidget.canvas.axes.set_xticklabels(temp['date'], rotation=90 )
self.MplWidget.canvas.axes.legend(loc='best')
self.MplWidget.canvas.draw()
this is my code to show pie chart
self.MplWidget.canvas.axes.title.set_text('pie graph')
self.MplWidget.canvas.axes.pie(sizes, labels=labels, autopct='%1.1f%%',shadow=True, startangle=90)
self.MplWidget.canvas.axes.axis('equal')
self.MplWidget.canvas.draw()
self.MplWidget.canvas.axes.clear()
Axes.pie sets the aspect ratio of the axes to 'equal' which is what seems to mess up the bar plot. You could try setting self.MplWidget.canvas.axes.set_aspect('auto') when plotting the bar plot to reset the aspect ratio to 'auto'. You probably also want to set self.MplWidget.canvas.axes.set_frame_on(True) since Axes.pie removes the frame around the plot as well.
Another option could be to use separate widgets for each of the plots and combine them in a QStackedWidget or QTabWidget.

Feature Pyramid Network with tensorflow/models/object_detection

If I want to implement k = k0 + log2(√(w*h)/224) in Feature Pyramid Networks for Object Detection, where and which file should I change?
Note, this formula is for ROI pooling. W and H are the width and height of ROI, whereas k represents the level of the feature pyramid this ROI should be used on.
*saying the FasterRCNN meta_architecture file of in object_detection might be helpful, but please inform me which method I can change.
Take a look at this document for a rough overview of the process. In a nutshell, you'll have to create a "FeatureExtractor" sub-class for you desired meta-architecture. For FasterRCNN, you can probably start with a copy of our Resnet101 Feature Extractor as a starting point.
The short answer is that the change won't be trivial as we don't currently support cropping regions from multiple layers. Here is an outline of what would need to change if you would like to pursue this anyway:
Generating a new anchor set
Currently Faster RCNN uses a “GridAnchorGenerator” as the first_stage_anchor_generator - instead you will have to use a MultipleGridAnchorGenerator (same as we use in SSD pipeline).
You will have to use a 32^2 anchor box -> for the scales field of the anchor generator, basically you will have to add a .125
You will have to modify the code to generate and crop from multiple layers: to start, look for a function in the faster_rcnn_meta_arch file called "_extract_rpn_feature_maps", which is suggestively named, but currently returns just a single tensor! You will also have to add some logic to determine which layer to crop from based on the size of the proposal (Eqn 1 from the paper)
You will have to finally create a new feature extractor following the directions that Derek linked to.

How can I get and set the position of a draggable legend in matplotlib

I'm trying to get and set the position of a draggable legend in matplotlib. My application consists of an interactive GUI, which has a redraw/plot function that should perform the follow steps:
save the position of the current legend.
clear the current axes and perform various plotting operations, which may or may add labels to their plots.
build a new draggable legend (ax.legend().draggable()) and restore the old position of the legend.
In between these steps the user is free to drag the legend around, and the goal is to persist the legend position when the plots are redrawn.
My first approach was to use oldpos = legend.get_bbox_to_anchor() and legend.set_bbox_to_anchor(oldpos) in steps 1 and 3. However this causes to move the legend completely off the visible area.
Note that I have to use ax.legend() and cannot use fig.legend(lines, labels), since step 2 is completely decoupled, i.e., I don't know anything about lines and labels in step 3. According to answers to the question How to position and align a matplotlib figure legend? there seems to be a difference between these two possibilities regarding axes or figure coordinates. Obviously my problem calls for figure coordinates, but I haven't fully understood how to convert the bbox to a "bbox in figure coordinates".
The even more severe problem I just realized is that apparently legend.get_bbox_to_anchor() always seems to return the same values irrespective of the drag position. So maybe the anchor can only be (ab-)used to manipulate the position of static legends? Is there another/proper way to save and restore the position of a draggable legend?
By looking at the implementation of Legend I found out that there is an undocumented property _loc, which exactly does what I want. My solution now looks astonishingly simple:
oldLegPos = ax.get_legend()._loc
# perform all plotting operations...
legend = ax.legend().draggable()
legend._loc = oldLegPos
It looks like _loc automatically stores figure coordinates, since I do not have to convert the coordinates in any way (eg. when the plotting operations completely change the axes ranges/coordinates).