logo
Tags down

shadow

Vega-Lite layered chart: how to get tick marks and tick labels to span the entire axis?


By : vijayant yadav
Date : September 13 2020, 08:00 PM
like below fixes the issue When you use a bin transform within an encoding, Vega-Lite adjusts the default axis properties to match the binning. You can re-adjust these manually via the encoding's scale and axis properties, but I think a simpler way is to move the bin transform to the chart's transform specification. Here is an example (Vega Editor):
code :
{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "data": {"url": "data/movies.json"},
  "transform": [
    {"calculate": "2*datum.IMDB_Rating", "as": "UpperLimit"},
    {
      "bin": true,
      "field": "IMDB_Rating",
      "as": ["IMDB_Rating_0", "IMDB_Rating_1"]
    }
  ],
  "layer": [
    {
      "mark": "bar",
      "encoding": {
        "x": {
          "field": "IMDB_Rating_0",
          "type": "quantitative",
          "bin": "binned"
        },
        "x2": {"field": "IMDB_Rating_1"},
        "y": {"aggregate": "count", "type": "quantitative"}
      }
    },
    {
      "mark": "rule",
      "encoding": {
        "x": {
          "aggregate": "max",
          "field": "UpperLimit",
          "type": "quantitative"
        },
        "color": {"value": "red"},
        "size": {"value": 5}
      }
    }
  ]
}


Share : facebook icon twitter icon

Matplotlib so log axis only has minor tick mark labels at specified points. Also change size of tick labels in colorbar


By : user3257308
Date : March 29 2020, 07:55 AM
I hope this helps you . 1) Use FixedLocator to statically define explicit tick locations.
2) Colorbar cbar will have an ax attribute that will provide access to the usual axis methods including tick formatting.
code :
import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)
x = np.arange(10,3000,100)
y = np.arange(10,3000,100)
X,Y = np.meshgrid(x,y)
Z = np.random.random(X.shape)*8000000
surf = ax.contourf(X,Y,Z, 8, cmap=plt.cm.jet)
ax.set_ylabel('Log Frequency (Hz)')
ax.set_xlabel('Log Frequency (Hz)')
ax.set_xscale('log')
ax.set_yscale('log')
ax.xaxis.set_minor_formatter(plt.FormatStrFormatter('%d'))
# defining custom minor tick locations:
ax.xaxis.set_minor_locator(plt.FixedLocator([50,500,2000]))
ax.yaxis.set_ticks_position('left')
ax.xaxis.set_ticks_position('bottom')
ax.tick_params(axis='both',reset=False,which='both',length=8,width=2)
cbar = fig.colorbar(surf, shrink=0.5, aspect=20, fraction=.12,pad=.02)
cbar.set_label('Activation',size=18)
# access to cbar tick labels:
cbar.ax.tick_params(labelsize=5) 
plt.show()
def show_only_some(x, pos):
    s = str(int(x))
    if s[0] in ('2','5'):
        return s
    return ''

ax.xaxis.set_minor_formatter(plt.FuncFormatter(show_only_some))

R, Change distance between axis tick marks and tick mark labels


By : Ryan Harmer
Date : March 29 2020, 07:55 AM
this will help Quick solution is to put las=2 in both your barplot() and axis() calls to make labels horizontal and they'll be clearer.
EDIT: Use mtext instead of axis:

Alternating length of axis tick marks in ggplot edit: major and minor tick marks


By : hasham.98
Date : March 29 2020, 07:55 AM
this will help Ok, got this figured out with help from jhoward above and this question.
The trick is to plot the minor tick marks in the original plot, then add the major tick marks using annotation_custom.
code :
# base plot
base <- ggplot(plots, aes(age,installation)) +
  geom_point() +
  scale_y_discrete(breaks=levels(plots$installation)[c(2,4,6,8,10)]) +
  scale_x_continuous(expand=c(0,1)) +
  theme(axis.text=element_text(size=10),
        axis.title.y=element_text(vjust=0.1))

# add the tick marks at every other facet level
for (i in 1:length(plots$installation)) {
  if(as.numeric(plots$installation[i]) %% 2 != 0) {
    base = base + annotation_custom(grob = linesGrob(gp=gpar(col= "dark grey")),  
                              ymin = as.numeric(plots$installation[i]), 
                              ymax = as.numeric(plots$installation[i]), 
                              xmin = -1.5, 
                              xmax = 0)
  }
}

# add the labels at every other facet level
for (i in 1:length(plots$installation)) {
  if(as.numeric(plots$installation[i]) %% 2 != 0) {
    base = base + annotation_custom(grob = textGrob(label = plots$installation[i], 
                                                    gp=gpar(col= "dark grey", fontsize=10)),  
                                    ymin = as.numeric(plots$installation[i]), 
                                    ymax = as.numeric(plots$installation[i]), 
                                    xmin = -2.5, 
                                    xmax = -2.5)
  }
}

# create the plot
gt <- ggplot_gtable(ggplot_build(base))
gt$layout$clip[gt$layout$name=="panel"] <- "off"
grid.draw(gt)

ggplot2: shorter tick marks for tick marks without labels (for y axis)


By : Schneider
Date : March 29 2020, 07:55 AM
I hope this helps you . The main issue is that you should be using marks = ticks$grobs[[2]]. There were some other issues with your code (which give's a warning 'data length is not a multiple of split variable') so here is a working minimal example:
code :
labs = seq(0,100,10)
labs[!!((seq_along(labs)-1)%%5)] = ''
g = ggplot(data.frame(x = 1:10, y = (1:10)^2), aes(x,y)) +
  geom_point() +
  scale_y_continuous(breaks = seq(0,100,10), labels = labs) +
  theme(axis.ticks.length=unit(10, "pt"))

gg = ggplotGrob(g)
yaxis <- gg$grobs[[which(gg$layout$name == "axis-l")]]  
ticks <- yaxis$children[[2]]
marks = ticks$grobs[[2]]
marks$x[c(2:5,7:10)*2-1] = unit(1, "npc") - unit(3, "pt")

# Put the tick marks back into the plot
ticks$grobs[[2]] = marks
yaxis$children[[2]] = ticks
gg$grobs[[which(gg$layout$name == "axis-l")]]  = yaxis
grid.draw(gg)

Altair/Vega-Lite tick chart: filter top K strips from aggregated field


By : user1296728
Date : March 29 2020, 07:55 AM
help you fix your problem Reading (and understanding) the documentation more in depth, I think I can state that what I asked is currently (June 2018) unfeasible with altair/Vega-Lite. Here it is my explanation...
Performing an aggregate transform on the data, is equivalent of adding a GROUP BY clause on a SQL query so we are no more able to associate to an encoded channel any “original” data field in its “unaggregated” form: when I try to refer to competition in the x channel this is therefore undefined.
code :
alt.Chart(df).mark_tick().encode(
    x=alt.X(field='competition',type='temporal', timeUnit='yearmonthdate'),
    y=alt.Y('Sport:N',
        sort=alt.SortField(field='count', order='ascending', op='sum')
    ),
).transform_aggregate(
    countX='count()',
    groupby=['Sport']
).transform_window(
    window=[{'op': 'rank', 'as': 'rank'}],
    sort=[{'field': 'countX', 'order': 'descending'}]
).transform_filter('datum.rank <= 3').transform_lookup(
    lookup='Sport',
    from_=alt.LookupData(data=df, key='Sport',
                         fields=['competition'])
)
[
  {"foo": 1, "bar": 1},
  {"foo": 1, "bar": 2},
  {"foo": null, "bar": 3}
]
{
  "type": "joinaggregate",
  "fields": ["foo", "bar", "bar"],
  "ops": ["valid", "sum", "median"],
  "as": ["v", "s", "m"]
}
[
  {"foo": 1, "bar": 1, "v": 2, "s": 6, "m": 2},
  {"foo": 1, "bar": 2, "v": 2, "s": 6, "m": 2},
  {"foo": null, "bar": 3, "v": 2, "s": 6, "m": 2}
]
Related Posts Related Posts :
  • Gremlin Python: Count vertices and its children in one query
  • How to trace the user's country using ip address he is using?
  • Can I frontload user input, automating Google Cloud SDK gcloud init - interactive command?
  • Why the resnet110 I train on CIFAR10 dataset only get 77% test acc
  • Error with simulation using INET in OMNeT++
  • gdrive command line oauth2: cannot fetch token: 400 Bad Request
  • How to generate a unique id in Ada?
  • Modelling a grammar with GADT, but type parameter won't unify
  • Limit Area to 10km from the center point - OpenLayers Map
  • selenium.JavascriptException: javascript error: Failed to execute 'elementFromPoint' on 'Document': The provided double
  • How can I use Asynchronous Widgets on jupyter lab?
  • Convert Payload with multiple Arrays into a single Array
  • Why zoom level returns decimal?
  • How to do pagination in Druid SQL
  • download data from website using uipath RPA
  • channel Got error &{FORBIDDEN} while joining new peer to a channel
  • How to ensure Screen reader announces capital letters
  • Can You Use a For Loop(s) to Optimize This Code?
  • Is there any way to see query profile for failed queries?
  • Is it possible make Watson Assistant search a data on IBM Cloudant?
  • Is there a way to append incrementally-changing numbers to div class?
  • Calling a Repast model with a list of model parameters
  • Best way to save the contents and configuration of a tk.Text widget?
  • Segmentation fault with openmp in Fortran 90 program
  • Instagram Feed in website - using Instagram Basic Display API
  • Emacs not filling out terminal framebuffer
  • How to instantly detect the key input in AHK?
  • Chisel compiled successfully but can't generate correctly verilog
  • AWS Cognito hosted UI returning id_token in URL
  • Not able to run theharvester on kali linux. Fatal exception: Pycurl: Link time version is older than compile time versio
  • QueryDSL wrong parenthesis with 'OR' and 'AND'
  • Trouble creating a basic clock app for Roku
  • Is there a way to get gerrit to reject commits without a JiRA ticket number?
  • How to print parameter in zimpl format file in lpsolve IDE?
  • How to access hashmap values from payload in dataweave 2.0?
  • Automatic Equation Numbering with MathJax v3.0
  • Unable to serialize IDictionary<string,obj> in ASP.Net Core 3.0 in F#
  • Chisel Synchronization
  • How can i prove that cons after uncons over coinductive list(a.k.a Stream) are identity, in Agda?
  • How to dispatch multiple actions from an effect in ngrx conditionally
  • Is it possible to have multiple valid access token with the same client credentials?
  • How Kafka Streams API get correct schema from Schema Registry?
  • How to cache Styles but still set individual text?
  • .grad() returns None in pytorch
  • Problem how to get the information of a message sent by Telegram
  • Choosing "As data in column" as file name option under Sink Settings for Data Flow is writing data at root of
  • PetitParser: How to match to token set
  • What do those sideways "L" in BBEdit's gutter area mean?
  • Clone Snowflake metadata only
  • Hello! Can someome explain this ```for i, v in pairs(name) do``` for me? Thanks
  • foldr vs foldl as reduce operator in APL
  • DDD, CQRS, Event Sourcing, Aggregates, Related Aggregates, and persistence
  • Uneditable box after ticking it
  • End expected but no clue
  • Extracting kdb list values based on some condition
  • Rounding results in OLS regression
  • How can I add a formula field in my NetSuiite saved search to show me where the invoice date is equal to the due date
  • How can I sorting the grouped rows based on the count of igGrid from infragistics ignite-ui? (jQuery)
  • GOP setting is not honored by Intel H264 hardware MFT
  • Input Parameter filtering with empty value
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk